snapshot-reference
The snapshot-reference
command captures the current state of the reference-url
database, which is the
The snapshot-reference
command has two modes:
- When run without options, it gathers the current state of the database and shows a text-based version of the schema to
STDOUT
. - When run with the
--snapshot-format=json
option, it creates a JSON file that represents the current state of thereference-url
database. Alternatively, you can have a YAML-based output by using the--snapshot-format=yaml
attribute.
Uses
The snapshot-reference
command is typically used when you want to see changes in your
You can use the output of snapshot-reference
with the diff and diff-changelog commands.
Note: It is best practice to use the --snapshot-format=json
option for the diff
and diff-changelog
commands. Otherwise, you will get only a text report of your target database. This text report cannot be used for comparison in the future.
It 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 by 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.
Syntax
To run the snapshot-reference
command, specify your driver, classpath, and URL in the Liquibase properties file. For more information, see Create and Configure a liquibase.properties File. You can also specify these properties in your command line.
Then run the snapshot-reference
command:
liquibase snapshot-reference
To create a JSON file, add the --snapshot-format=json
attribute:
liquibase --output-file=mySnapshot.json snapshot-reference --snapshot-format=json
Parameters
Global parameters
Attribute | Definition | Requirement |
---|---|---|
|
File path to where the command output will be written. If not specified, output goes to |
Optional |
Command parameters
Attribute | Definition | Requirement |
---|---|---|
|
The JDBC reference database connection URL |
Required |
|
The reference default catalog name to use for the database connection |
Optional |
|
The reference default schema name to use for the database connection |
Optional |
|
The JDBC driver class |
Optional |
|
The JDBC driver properties file |
Optional |
|
Reference database catalog to use for Liquibase objects. Liquibase 4.24.0+. |
Optional |
|
Reference database schema to use for Liquibase objects. Liquibase 4.24.0+. |
Optional |
|
The reference database password. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
Optional |
|
The reference database username. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
Optional |
|
Liquibase Pro 4.26.0+. Controls which types of objects Liquibase includes in the snapshot. Can improve command performance. Specify multiple values in a comma-separated list. Accepted values are: |
Optional |
|
Output format to use. Creates a file of the specified type that represents the current state of the database. Valid values: |
Optional |
Global parameters
Attribute | Definition | Requirement |
---|---|---|
|
File path to where the command output will be written. If not specified, output goes to |
Optional |
Command parameters
Attribute | Definition | Requirement |
---|---|---|
|
The JDBC reference database connection URL |
Required |
|
The reference default catalog name to use for the database connection |
Optional |
|
The reference default schema name to use for the database connection |
Optional |
|
The JDBC driver class |
Optional |
|
The JDBC driver properties file |
Optional |
|
Reference database catalog to use for Liquibase objects. Liquibase 4.24.0+. |
Optional |
|
Reference database schema to use for Liquibase objects. Liquibase 4.24.0+. |
Optional |
|
The reference database password. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
Optional |
|
The reference database username. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
Optional |
|
Liquibase Pro 4.26.0+. Controls which types of objects Liquibase includes in the snapshot. Can improve command performance. Specify multiple values in a comma-separated list. Accepted values are: |
Optional |
|
Output format to use. Creates a file of the specified type that represents the current state of the database. Valid values: |
Optional |
Global parameters
Attribute | Definition | Requirement |
---|---|---|
|
File path to where the command output will be written. If not specified, output goes to |
Optional |
Command parameters
Attribute | Definition | Requirement |
---|---|---|
|
The JDBC reference database connection URL |
Required |
|
The reference default catalog name to use for the database connection |
Optional |
|
The reference default schema name to use for the database connection |
Optional |
|
The JDBC driver class |
Optional |
|
The JDBC driver properties file |
Optional |
|
Reference database catalog to use for Liquibase objects. Liquibase 4.24.0+. |
Optional |
|
Reference database schema to use for Liquibase objects. Liquibase 4.24.0+. |
Optional |
|
The reference database password. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
Optional |
|
The reference database username. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
Optional |
|
Liquibase Pro 4.26.0+. Controls which types of objects Liquibase includes in the snapshot. Can improve command performance. Specify multiple values in a comma-separated list. Accepted values are: |
Optional |
|
Output format to use. Creates a file of the specified type that represents the current state of the database. Valid values: |
Optional |
Global parameters
Attribute | Definition | Requirement |
---|---|---|
|
File path to where the command output will be written. If not specified, output goes to |
Optional |
Command parameters
Attribute | Definition | Requirement |
---|---|---|
|
The JDBC reference database connection URL |
Required |
|
The reference default catalog name to use for the database connection |
Optional |
|
The reference default schema name to use for the database connection |
Optional |
|
The JDBC driver class |
Optional |
|
The JDBC driver properties file |
Optional |
|
Reference database catalog to use for Liquibase objects. Liquibase 4.24.0+. |
Optional |
|
Reference database schema to use for Liquibase objects. Liquibase 4.24.0+. |
Optional |
|
The reference database password. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
Optional |
|
The reference database username. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
Optional |
|
Liquibase Pro 4.26.0+. Controls which types of objects Liquibase includes in the snapshot. Can improve command performance. Specify multiple values in a comma-separated list. Accepted values are: |
Optional |
|
Output format to use. Creates a file of the specified type that represents the current state of the database. Valid values: |
Optional |
Global parameters
Attribute | Definition | Requirement |
---|---|---|
|
File path to where the command output will be written. If not specified, output goes to |
Optional |
Command parameters
Attribute | Definition | Requirement |
---|---|---|
|
The JDBC reference database connection URL |
Required |
|
The reference default catalog name to use for the database connection |
Optional |
|
The reference default schema name to use for the database connection |
Optional |
|
The JDBC driver class |
Optional |
|
The JDBC driver properties file |
Optional |
|
Reference database catalog to use for Liquibase objects. Liquibase 4.24.0+. |
Optional |
|
Reference database schema to use for Liquibase objects. Liquibase 4.24.0+. |
Optional |
|
The reference database password. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
Optional |
|
The reference database username. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
Optional |
|
Liquibase Pro 4.26.0+. Controls which types of objects Liquibase includes in the snapshot. Can improve command performance. Specify multiple values in a comma-separated list. Accepted values are: |
Optional |
|
Output format to use. Creates a file of the specified type that represents the current state of the database. Valid values: |
Optional |
Note: The username
and password
attributes are not required for connections and systems which use alternate means of authentication. Also, you can specify database credentials as part of the url
attribute.
Using snapshot-reference
in the diff-changelog
commands
You can use the JSON format snapshot file in the diff
and diff-changelog
commands. One of the typical workflows is the following:
- Make sure your local environment is up-to-date by getting the latest changelog from source control.
- Configure the Liquibase properties file to point to a local development database and run the
update
command to ensure yoursource
database matches the changelog file. - Take a snapshot of the local development database by running the
snapshot-reference
command: - Manually change the local development database if needed.
- Append changes to the changelog by running the
diff-changelog
command: - Review the changelog file to ensure that it matches your expectations of the manual changes that were made.
- Mark the manual changes as deployed in the local development database by running the changelog-sync command:
- Commit the changes to the source control.
liquibase --output-file=myschemaSnapshot.json snapshot-reference --snapshot-format=json
liquibase diff-changelog --reference-url=jdbc:oracle:thin://localhost:9090/mem:test --url="offline:oracle?snapshot=mySnapshot.json"
Note: If you want to see changes without appending them to the changelog file, add --changelog-file=mydiffchangelog.xml
to the diff-changelog
command:
liquibase diff-changelog --reference-url=jdbc:oracle:thin://localhost:9090/mem:test --url="offline:oracle?snapshot=mySnapshot.json" --changelog-file=mydiffchangelog.xml
Note: The format for the URL is the following: "offline:<db_type>?snapshot=<path/to/snapshot.json>"
(with quotes). Use the name of your database type from the list of the supported databases in place of <db_type>
and the path relative to where the command is running in place of <path/to/snapshot.json>
.
liquibase changelog-sync
Liquibase Open Source snapshot-reference
categories:
- Catalog
- Column
- Foreign Key
- Index
- Primary Key
- Schema
- Sequence
- Unique Constraints
- View
Liquibase Pro snapshot-reference
categories:
- Package
- Package Body
- Procedures
- Function
- Trigger
- Synonyms
- Check Constraints
When running the snapshot-reference
command with the --snapshot-format
attribute, the output can be as follows:
Liquibase Community 4.9.1 by Liquibase
Output saved to C:\Users\Amber Williams\Documents\Maven_h2\mySnapshot.json
Liquibase command 'snapshot-reference' was executed successfully.
When running the snapshot-reference
command without indicating the --snapshot-format
, you receive the following output:
Liquibase Community 4.9.1 by Liquibase
Database snapshot for jdbc:h2:tcp://localhost:9090/mem:integration
-----------------------------------------------------------------
Database type: H2
Database version: 2.1.210 (2022-01-17)
Database user: DBUSER
Included types:
liquibase.structure.core.Catalog
liquibase.structure.core.Column
liquibase.structure.core.ForeignKey
liquibase.structure.core.Index
liquibase.structure.core.PrimaryKey
liquibase.structure.core.Schema
liquibase.structure.core.Sequence
liquibase.structure.core.Table
liquibase.structure.core.UniqueConstraint
liquibase.structure.core.View
Liquibase command 'snapshot-reference' was executed successfully.
The snapshot-reference
command produces a JSON file that contains all your objects and places the file in the same directory as your changelog.
Database snapshot for jdbc:h2:tcp://localhost:9090/mem:integration
-----------------------------------------------------------------
Database type: H2
Database version: 2.1.210 (2022-01-17)
Database user: DBUSER
Included types:
liquibase.structure.core.Catalog
liquibase.structure.core.Column
liquibase.structure.core.ForeignKey
liquibase.structure.core.Index
liquibase.structure.core.PrimaryKey
liquibase.structure.core.Schema
liquibase.structure.core.Sequence
liquibase.structure.core.Table
liquibase.structure.core.UniqueConstraint
liquibase.structure.core.View