Ant changeLogSyncToTag
The changeLogSyncToTag
task marks all undeployed changesets from your changelog up to the specified tag as executed in your database. The task 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 Types as follows:
<changeSet id="13.1" author="liquibase">
<tagDatabase tag="version_2.0"/>
</changeSet>
Uses
The changeLogSyncToTag
task is typically used when you want to baseline a new database environment with specific objects. An example use case for the changeLogSyncToTag
task 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
changeLogSyncToTag
task to mark the changes related to that tag as executed in the DATABASECHANGELOG table. - The task 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 Ant changeLogSync task.
You can also use the changeLogSyncToTag
task 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.
Syntax
To execute the changeLogSyncToTag
task, include the following values in your Ant default file, which can be build.xml
:
<project name="Example" xmlns:liquibase="antlib:liquibase.integration.ant">
<taskdef resource="liquibase/integration/ant/antlib.xml" uri="antlib:liquibase.integration.ant">
<classpath path="path/to/liquibase/libs"/>
</taskdef>
<property name="db.changelog.file" value="changelog.xml" />
<target name="changeLogSyncToTag" depends="prepare">
<liquibase:database
id="my-database"
driver="${driver.classname}"
url="${jdbc.url}"
user="${username}"
password="${password}"/>
<liquibase:changeLogSyncToTag
databaseref="my-database"
changeLogFile="com/example/changelog.xml"
labelFilter="mylabels"
toTag="version_1.1"
classpathref="classpath"/>
</target>
</project>
This example will sync the referenced database with the changesets found in the changelog file up to and including the tag changeset.
Next, run the following in the CLI to implement the task and update your database:
ant -f build.xml changeLogSyncToTag
Note: It is important to type the task name in the command prompt exactly like you specify it in the target name of your build.xml
file. Ant uses the task name to determine which Liquibase command it will run.
Attributes
Attribute | Description | Required |
---|---|---|
changelogFile
|
The changelog file for Liquibase to use. | Yes |
toTag
|
Syncs the changesets up to and including the tag. | Yes |
contexts
|
A comma-separated list of Contexts to execute. If not specified, all contexts are run. | No |
outputFile
|
If specified, Liquibase will save the update SQL statements to the specified file rather than executing them in the database. | No |
outputEncoding
|
The character encoding to use when writing to output file. | No. Defaults to system encoding. |
promptOnNonLocalDatabase
|
If set to true, a dialog box with warn you if you attempt to run the Liquibase against a database that is not on localhost. | No. The default value is set to false. |
classpathref
|
A reference to the classpath used to run the task with. | No |
databaseref
|
A reference to the database that Liquibase will connect to. | Yes, unless a nested <database> element is present. |
driver
|
Deprecated: Name of the database driver to connect with. | No |
url
|
Deprecated: Use <database> 's url attribute instead. The database URL.
|
No |
username
|
Deprecated: The database username to connect with. | No |
password
|
Deprecated: The password to use when connecting to the database. | No |
defaultSchemaName
|
Deprecated: Schema to use by default for managed database objects and Liquibase control tables. | No |
currentDateTimeFunction
|
Deprecated: Overrides current date time function used in SQL. Useful for unsupported databases. | No |
databaseChangeLogTableName
|
Deprecated: Overrides the name of the DATABASECHANGELOG table to use. | No |
databaseChangeLogLockTableName
|
Deprecated: Overrides the name of the DATABASECHANGELOGLOCK table to use. | No |
logLevel
|
Deprecated: Specifies one of the following logging levels: debug, info, warning, severe, off. The default level is info. | No |
Nested attributes
Attribute | Description | Required |
---|---|---|
classpath
|
The classpath used to run the task. | Optional |
database
|
See database data type for more information. | Required unless a databaseref attribute is given. |
changelogparameters
|
See Substituting Properties in Changelogs for more information. | Optional |