changelog-sync-to-tag
The changelog-sync-to-tag
command marks all undeployed changesets from your changelog up to the specified tag as executed in your database. The command also marks the changeset with that tag as deployed.
Note: If you don't have any tag specified in your changelog file, add it by using the tagDatabase
Change Type as follows:
<changeSet id="13.1" author="liquibase">
<tagDatabase tag="version_2.0"/>
</changeSet>
Uses
The changelog-sync-to-tag
command is typically used when you want to baseline a new database environment with specific objects. An example use case for the changelog-sync-to-tag
command is the following:
- You have a DEV environment with a set of objects used only in DEV, and you want to use the same changelog to manage a new TEST environment. The TEST environment does not have those DEV-only objects and needs only some of them.
- To deploy the needed DEV-only objects and avoid deploying the rest, you add a tag and run the
changelog-sync-to-tag
command to mark the changes related to that tag as executed in the DATABASECHANGELOG table (DBCL). - The command marks all changesets starting with the first changeset at the top of the DEV changelog file and moving down to the changesets up to and including the tag.
- Next, you deploy the changesets that were not marked as deployed in your database. Liquibase treats your DEV and TEST databases as equivalent.
Note: If you want to mark all undeployed changes from the changelog file as executed in your database, use the changelog-sync command.
You can also use the changelog-sync-to-tag
command to mark the change associated with a specific tag as executed if the object associated with the change was created manually on the database. By marking the changeset as executed, it prevents the next Liquibase update from failing as it tries to create an object that already exists.
Command behavior
You must specify a tag with the tagDatabase
Change Type in your changelog file for changelog-sync-to-tag
to work:
- If you specify
tagDatabase
in your changelog,changelog-sync-to-tag
adds rows to the DBCL table for every changeset up to that tag. - If you omit
tagDatabase
from your changelog,changelog-sync-to-tag
adds rows to the DBCL table for all changes. - If you misspell the tag from
tagDatabase
when you run the command,changelog-sync-to-tag
adds rows to the DBCL table for all changes.
If Liquibase cannot find your tag, it displays the following message:
changelog-sync-to-tag: Liquibase command 'changelog-sync-to-tag' was executed successfully.
Tip: Before running this command, it is a best practice to run tag-exists
to check whether your tag syntax is correct. It is also a best practice to copy+paste the name of the tag into the CLI so that you are less likely to misspell it.
Syntax
Before running the changelog-sync-to-tag
command, specify the 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.
Next, run the changelog-sync-to-tag
command:
liquibase changelog-sync-to-tag --tag=myTag --changelog-file=example-changelog.xml
Note: The --tag=myTag
syntax was added in Liquibase 4.4. If you use an older version, specify your tag as a positional argument: <command> myTag
.
Command parameters
Attribute | Definition | Requirements |
---|---|---|
|
The root changelog |
Required |
|
The tag identifying which tagged changesets in the changelog to evaluate. Specify as |
Required |
|
The JDBC database connection URL. See Using JDBC URL in Liquibase. |
Required |
|
Specifies the changeset contexts to match. Contexts are tags you can add to changesets to control which changesets are executed in any particular migration run. Note: If you use Liquibase 4.23.0 or earlier, use the syntax |
Optional |
|
Name of the default catalog to use for the database connection |
Optional |
|
Name of the default schema to use for the database connection. If Tip: In Liquibase v4.23.0+, camelCase for Note: The syntax |
Optional |
|
The JDBC driver class |
Optional |
|
The JDBC driver properties file |
Optional |
|
Specifies the changeset labels to match. Labels are tags you can add to changesets to control which changesets will be executed in any migration run. |
Optional |
|
Password to connect to the target database. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
Optional |
|
Username to connect to the target database. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
Optional |
Attribute | Definition | Requirements |
---|---|---|
|
The root changelog |
Required |
|
The tag identifying which tagged changesets in the changelog to evaluate. Specify as |
Required |
|
The JDBC database connection URL. See Using JDBC URL in Liquibase. |
Required |
|
Specifies the changeset contexts to match. Contexts are tags you can add to changesets to control which changesets are executed in any particular migration run. Note: If you use Liquibase 4.23.0 or earlier, use the syntax |
Optional |
|
Name of the default catalog to use for the database connection |
Optional |
|
Name of the default schema to use for the database connection. If Tip: In Liquibase v4.23.0+, camelCase for Note: The syntax |
Optional |
|
The JDBC driver class |
Optional |
|
The JDBC driver properties file |
Optional |
|
Specifies the changeset labels to match. Labels are tags you can add to changesets to control which changesets will be executed in any migration run. |
Optional |
|
Password to connect to the target database. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
Optional |
|
Username to connect to the target database. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
Optional |
Attribute | Definition | Requirements |
---|---|---|
|
The root changelog |
Required |
|
The tag identifying which tagged changesets in the changelog to evaluate. Specify as |
Required |
|
The JDBC database connection URL. See Using JDBC URL in Liquibase. |
Required |
|
Specifies the changeset contexts to match. Contexts are tags you can add to changesets to control which changesets are executed in any particular migration run. Note: If you use Liquibase 4.23.0 or earlier, use the syntax |
Optional |
|
Name of the default catalog to use for the database connection |
Optional |
|
Name of the default schema to use for the database connection. If Tip: In Liquibase v4.23.0+, camelCase for Note: The syntax |
Optional |
|
The JDBC driver class |
Optional |
|
The JDBC driver properties file |
Optional |
|
Specifies the changeset labels to match. Labels are tags you can add to changesets to control which changesets will be executed in any migration run. |
Optional |
|
Password to connect to the target database. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
Optional |
|
Username to connect to the target database. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
Optional |
Attribute | Definition | Requirements |
---|---|---|
|
The root changelog |
Required |
|
The tag identifying which tagged changesets in the changelog to evaluate. Specify as |
Required |
|
The JDBC database connection URL. See Using JDBC URL in Liquibase. |
Required |
|
Specifies the changeset contexts to match. Contexts are tags you can add to changesets to control which changesets are executed in any particular migration run. Note: If you use Liquibase 4.23.0 or earlier, use the syntax |
Optional |
|
Name of the default catalog to use for the database connection |
Optional |
|
Name of the default schema to use for the database connection. If Tip: In Liquibase v4.23.0+, camelCase for Note: The syntax |
Optional |
|
The JDBC driver class |
Optional |
|
The JDBC driver properties file |
Optional |
|
Specifies the changeset labels to match. Labels are tags you can add to changesets to control which changesets will be executed in any migration run. |
Optional |
|
Password to connect to the target database. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
Optional |
|
Username to connect to the target database. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
Optional |
Attribute | Definition | Requirements |
---|---|---|
|
The root changelog |
Required |
|
The tag identifying which tagged changesets in the changelog to evaluate. Specify as |
Required |
|
The JDBC database connection URL. See Using JDBC URL in Liquibase. |
Required |
|
Specifies the changeset contexts to match. Contexts are tags you can add to changesets to control which changesets are executed in any particular migration run. Note: If you use Liquibase 4.23.0 or earlier, use the syntax |
Optional |
|
Name of the default catalog to use for the database connection |
Optional |
|
Name of the default schema to use for the database connection. If Tip: In Liquibase v4.23.0+, camelCase for Note: The syntax |
Optional |
|
The JDBC driver class |
Optional |
|
The JDBC driver properties file |
Optional |
|
Specifies the changeset labels to match. Labels are tags you can add to changesets to control which changesets will be executed in any migration run. |
Optional |
|
Password to connect to the target database. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
Optional |
|
Username to connect to the target database. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
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.
Output
When successful, the changelog-sync-to-tag
command produces the following output:
Liquibase Version: 4.9.1
Liquibase command 'changelog-sync-to-tag' was executed successfully.