diff command

The diff command in Liquibase allows you to compare two databases of the same type, or different types, to one another.

Uses

The diff command is typically used at the completion of a project to verify all expected changes are in the changelog or to detect drift between a model schema and a database's actual schema. The diff command is also useful for the following tasks:

  • Finding missing objects between one database and another
  • Seeing that a change was made to your database
  • Finding unexpected items in your database

Running the diff command

Running the diff command requires two URLs:

  • referenceURL – the source for the comparison. The referenceURL attribute represents your source database which is the starting point and the basis for the database you want to compare.

  • url – the target of the comparison. The url attribute stands for your target database which you want to compare to the source database. You typically perform actions and run the commands against this database

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. You can do this by running the following:
liquibase
--outputFile=mydiff.txt
--driver=oracle.jdbc.OracleDriver
--classpath=ojdbc14.jar
--url="jdbc:oracle:thin:@<IP OR HOSTNAME>:<PORT>:<SERVICE NAME OR SID>"
--username=<USERNAME>
--password=<PASSWORD>
--referenceUrl="jdbc:oracle:thin:@<IP OR HOSTNAME>:<PORT>:<SERVICE NAME OR SID>"
--referenceUsername=<USERNAME>
--referencePassword=<PASSWORD>
				
diff

See the snapshot command documentation for an example of using a snapshot file as one of the databases being used in the command.

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:
liquibase --outputFile=mydiff.txt diff

Note: For information on how to configure your liquibase.properties file, view the Creating and configuring a liquibase.properties file topic.

The diff command produces a list of categories along with one of the following descriptions:

  • Missing: there are objects on your source database (referenceURL) that are not on your target database (url).
  • Unexpected: there are objects on your target database (url) that are not on your source database (referenceURL).
  • Changed: the object as it exists on the source database (referenceURL) is different than as it exists in the target database (url).

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:

  • Catalog
  • Column
  • Foreign Key
  • Index
  • Primary Key
  • Schema
  • Sequence
  • Procedure
  • Unique Constraints
  • View

Liquibase Pro diff categories:

  • Check Constraint
  • Package
  • Package Body
  • Function
  • Trigger
  • Synonyms

Note: Liquibase does not currently check datatype length.

Filtering diff types

Liquibase allows you to use diffType attributes to filter the types of objects you want to compare. Multiple filters can be added to the attribute as a comma separated list. If no diffTypes are specified, all objects are considered.

Example: liquibase --diffTypes=tables,indexes,views diff

Related Links