The diff command in Liquibase allows you to compare two databases of the same type or different types to one another.
The diff command is typically used at the completion of a project, because it allows you to verify all expected changes are in the changelog. The diff command is also useful for the following tasks:
Finding missing objects in your database
Seeing that a change was made to your database
Finding unexpected items in your database
Running the diff Command
To compare two databases:
The first option is to run the diff command and pass the parameters needed for your source database and target database. For example:
Run the following:
Note: When running diff against two different databases, the class path property should reference both .jar files. Use the path separator that is correct
for your operating system (a semicolon on Windows, a colon on Mac or Linux). Example: classpath: ojdbc7.jar:postgresql-42.2.8.jar
Alternatively, configure the liquibase.properties file to include your driver class path, URL, and user authentication information for both databases.
Run the following command:
The diff command produces a list of categories along with one of the following descriptions:
Missing: The object is not on your comparison database (source database).
Unexpected: There are objects on your comparison database (source database) that are not on your reference database (target database).
Changed: The object as it exists on the source database is different than as it exists in the target database.
Note: The changed description will not specify the type of change applied to your database. Run the diffChangeLog command
to generate a changelog that will apply the changes to the target database.
Liquibase Community diff categories:
Liquibase Pro diff categories:
Note: Liquibase does not currently check Datatype length.
Filtering diff Types
Liquibase allows you to use diffType parameters to filter the types of objects you want to compare. Multiple filters can be added
to the parameter as a comma separated list. If no diffTypes are specified, all objects are considered.