Redgate Flyway

Compare two databases

Flyway Enterprise

You can compare the schema in two different databases using the Flyway CLI.

This is available for SQL Server, Oracle, PostgreSQL, and MySQL databases.

Step-by-step guide

Option 1: Take two snapshots and generate a changes report

  1. Take a Snapshot of your source database.
    flyway snapshot -url=<jdbc:example:database_source> -user=<username> -password=<password> -snapshot.filename=<C:\snapshots\snapshot_source>
  2. Take a Snapshot of your target database.
    flyway snapshot -url=<jdbc:example:database_target> -user=<username> -password=<password> -snapshot.filename=<C:\snapshots\snapshot_target>
  3. Use the Check Changes report to compare the two snapshots and identify any differences between the two database schema snapshots.
    flyway check -changes -check.nextSnapshot="snapshot_source" -check.deployedSnapshot="snapshot_target"
      

Option 2: Use the flyway diff in combination with flyway prepare to generate a deployment script.

  1. Run a flyway diff, which will output a diff to the console.

    flyway diff (specifying databases directly)

    flyway diff
    "-environments.development.url=jdbc:sqlserver://localhost:1433;encrypt=false;databaseName=Dev"
    "-environments.development.user=sa"
    "-environments.development.password=..."
    "-environments.prod.url=jdbc:sqlserver://localhost:1433;encrypt=false;databaseName=Prod"
    "-environments.prod.user=sa"
    "-environments.prod.password=..."
    "-diff.source=development"
    "-diff.target=prod"
    Or alternatively, you can diff the snapshots created in option 1.

    flyway diff (snapshots)

    flyway diff -diff.source="snapshot:snapshot_source" -diff.target="snapshot:snapshot_target"
  2. Run flyway prepare to generate a deployment script (named D__deployment.sql by default), which when applied will make the target environment the same as the source.

    flyway prepare

    flyway prepare



Didn't find what you were looking for?