snapshot command has two modes:
- When run without options, it will gather the current state of the database and show a text-based version of the schema to
run with the
--snapshotFormat=JSONoption, creates a JSON file that represents the current state of your database.
snapshot command is typically used when you want to quickly compare changes in your database or keep a record of your current database state. Snapshots can also be used to compare:
- A previous database state to an online database.
- A previous database state to another snapshot.
Note: Running a
diff command using at least one snapshot.json file is faster than using a
diff command with two online databases. However, keep in mind that a snapshot will no
longer reflect the current state of the database if the database is changed with the
update command or if it is changed manually.
To take a snapshot of your database:
- Configure the liquibase.properties file to include your driver class path, URL, and user authentication information for your database.
Note: For information on how to configure your liquibase.properties file, view the Creating and configuring a liquibase.properties file topic in the knowledge base.
- Run the following command:
liquibase --outputFile=myschemaSnapshot.json snapshot --snapshotFormat=json
Using the snapshot in the diff and
You can use the JSON format snapshot file in the diff and
diffChangeLog commands. One typical workflow is:
- Make sure your local environment is up-to-date by getting the latest changelog from source control.
- Configure your liquibase.properties to point to a local development database and run
liquibase updateto ensure it has the latest schema.
- Take a snapshot of the local development database with
liquibase --outputFile=before.json snapshot --snapshotFormat=json
- Make manual changes to the local development database as needed.
- Add the manual changes to the changelog with
liquibase --url=jdbc:oracle:thin://localhost:9090/mem:test --referenceUrl=offline:mysql?snapshot=before.json diffChangeLog.
- Review the changelog to ensure that it matches your expectations of the manual changes made.
- Mark the manual changes as deployed in the local development database by running
- Commit the changes to source control.
The format for the database URL when using a snapshot is:
<dbtype> in that URL should be the Type Name from the list of supported databases, and the
<path/to/snapshot.json> is a path relative to where the command is running.
snapshot command produces a JSON file that contains all your objects and places the file in the same directory as your changelog.
- Foreign Key
- Primary Key
- Unique Constraints
- Package Body
- Check Constraints