changeLogSyncToTagSQL Task

changeLogSyncToTagSQL is a helper task that produces the raw SQL that Liquibase would run when using the changeLogSyncToTag task to mark all undeployed changesets associated with the specified tag as executed in your database.


The changeLogSyncToTagSQL task is typically used when you want to inspect the SQL Liquibase will use to baseline a new database environment.

It is best practice to inspect any SQL that Liquibase would run when using the changeLogSyncToTag task so you can review any changes the task would make to your database before running it. The changeLogSyncToTag task marks all changesets starting with the first changeset at the top of the changelog file and moving down to the changeset up to and including the tag.

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"/>

Running the changeLogSyncToTagSQL task

To execute the changeLogSyncToTagSQL 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"/>
<property name="db.changelog.file" value="oracle_lbpro_master_changelog.xml" />
<target name="changeLogSyncToTagSQL" depends="prepare">
   <liquibase:database id="my-database" driver="${driver.classname}"  url="${jdbc.url}" user="${username}" password="${password}"/>
   <liquibase:changeLogSyncToTagSQL databaseref="my-database" changelogfile="com/example/oracle_lbpro_master_changelog.xml"

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 changeLogSyncToTagSQL

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.


Attribute Description Required
changeLogFile The changelog file to run. Yes
toTag The attribute that 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 The file where Liquibase will save the update SQL statements rather than executing them in the database. No
outputEncoding The character encoding to use when writing SQL statements to output file. No. Defaults to system encoding.
promptOnNonLocalDatabase A dialog box that will send you a warn message if set to true and you attempt to run 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. No
databaseref A reference to the database to which the Liquibase will connect. Yes, unless a nested <database> element is present.
driver Deprecated: The name of the database driver with which you connect. No
url Deprecated: Use the database urlattribute instead. The database URL. No
username Deprecated: The database username with which you connect. No
password Deprecated: The password to use when connecting to the database. No
defaultSchemaName Deprecated: The schema to use by default for managed database objects and Liquibase control tables. No
currentDateTimeFunction Deprecated: Overrides the 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

Attributes specified as nested elements

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 changelog Property Substitution for more information. Optional