future-rollback-from-tag-sql
The future-rollback-from-tag-sql
command is a helper command that produces the raw SQL Liquibase would need to roll back all undeployed changes made up to the specified tag.
Uses
You can use the future-rollback-from-tag-sql
command to inspect the raw SQL Liquibase would use to revert changes associated with undeployed changesets. It is similar to the future-rollback-sql
command, except that you can use the tag
attribute to exclude some undeployed changesets from the SQL output.
You must specify a tag with the tag
command or the tagDatabase
Change Type in your changelog file for future-rollback-from-tag-sql
to work. If Liquibase cannot find your tag, it halts and displays the following message:
future-rollback-from-tag-sql: Unexpected error running Liquibase: No tag matching 'doesntexist' found
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.
Tip: When you run future-rollback-from-tag-sql
, check whether you specified the correct tag and whether any changesets were rolled back. (If you specify a tag that Liquibase cannot find in your changelog, the rollback
command halts.)
It is best practice to inspect the SQL Liquibase runs when using the update
command so you can review any changes the command would make to your database.
Note: The update-sql
command is a helper command that you can use before running the update
command. The main difference is that update-sql
creates objects associated with undeployed changesets, and future-rollback-from-tag-sql --tag=<tag>
drops objects associated with undeployed changesets.
Syntax
To run the future-rollback-from-tag-sql
command, specify the driver, classpath, and database 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.
Using an XML, YAML, or JSON changelog, create a new changeset containing the tagDatabase
Change Type with the tag
attribute. Any undeployed changesets before and including the tag will be included in the SQL output, and any undeployed changesets after the tag will be excluded.
Then run the future-rollback-from-tag-sql
command:
liquibase future-rollback-from-tag-sql --tag=myTag --changelog-file=example-changelog.xml --output-file=example-file.txt
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
.
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 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 |
|
Control whether names of objects in the default
catalog are fully qualified or not. If |
Optional |
|
Control whether names of objects in the default
schema are fully qualified or not. If |
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 |
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 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 |
|
Control whether names of objects in the default
catalog are fully qualified or not. If |
Optional |
|
Control whether names of objects in the default
schema are fully qualified or not. If |
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 |
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 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 |
|
Control whether names of objects in the default
catalog are fully qualified or not. If |
Optional |
|
Control whether names of objects in the default
schema are fully qualified or not. If |
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 |
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 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 |
|
Control whether names of objects in the default
catalog are fully qualified or not. If |
Optional |
|
Control whether names of objects in the default
schema are fully qualified or not. If |
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 |
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 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 |
|
Control whether names of objects in the default
catalog are fully qualified or not. If |
Optional |
|
Control whether names of objects in the default
schema are fully qualified or not. If |
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 |
*Liquibase checks nested changelogs for definitions of the changesets to rollback.
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.
-- *********************************************************************
-- SQL to roll back currently unexecuted changes
-- *********************************************************************
-- Change Log: changelog.xml
-- Ran at: 6/10/21, 1:59 PM
-- Against: DBUSER@jdbc:h2:tcp://localhost:9090/mem:dev
-- Liquibase version: 4.4.0
-- *********************************************************************
-- Lock Database
UPDATE PUBLIC.DATABASECHANGELOGLOCK SET LOCKED = TRUE, LOCKEDBY = 'DESKTOP-IJRALVU (192.168.56.1)', LOCKGRANTED = '2021-06-10 13:59:49.307' WHERE ID = 1 AND LOCKED = FALSE;
-- Rolling Back ChangeSet: changelog.xml::3::adrian
DELETE FROM PUBLIC.DATABASECHANGELOG WHERE ID = '3' AND AUTHOR = 'adrian' AND FILENAME = 'changelog.xml';
-- Rolling Back ChangeSet: changelog.xml::2::adrian
DROP TABLE PUBLIC.company;
DELETE FROM PUBLIC.DATABASECHANGELOG WHERE ID = '2' AND AUTHOR = 'adrian' AND FILENAME = 'changelog.xml';
-- Release Database Lock
UPDATE PUBLIC.DATABASECHANGELOGLOCK SET LOCKED = FALSE, LOCKEDBY = NULL, LOCKGRANTED = NULL WHERE ID = 1;
Liquibase command 'future-rollback-from-tag-sql' was executed successfully.