Compare a single database's current state against a previous state
If the database is accessible outside of the Liquibase process either via a hotfix pipeline or DBAs/developers have access to the database, it is possible for the Liquibase project to become out of sync with the target database. This option can also determine if code has been deployed to the database outside of the Liquibase process.
Procedure
Variable descriptions for the example commands:
$targetURL: This is the normal JDBC URL used to connect to the database.
<db_type>: This value needs to be set to the type of database (Postgres, Oracle, etc.).
This value is referred to as the DBMS or "shortname," which can be found for all supported databases.
<snapshot_file_name>: the snapshot file containing the current state of the database in a JSON format.
<changelog_file_name>: the generated changelog (set to SQL) containing changesets that are not in the database.
Run the update command on the target database.
liquibase --url=$targetURL update
Run the snapshot command to capture the current state of the database.
liquibase --url=$targetURL --output-file=.json snapshot --snapshot-format=json
Run a diff-changelog to compare the snapshot to the target database.
liquibase --url="offline:?snapshot=..." --reference-url=$targetURL diff-changelog --changelog-file=.sql
Note: If this is being used inside of an automation pipeline, this diff-changelog
command should be run either in a separate job than the Liquibase update, or it should be run before the update in step 1 to determine if changes have occurred in the database.