future-rollback-sql
The future-rollback-sql
command is a helper command that produces the raw SQL Liquibase would need to roll back changes that have not yet been deployed to your database.
Uses
You can use the future-rollback-sql
command to inspect the raw SQL Liquibase would use to revert changes associated with undeployed changesets.
It is best practice to inspect SQL Liquibase would run 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 also use before running the update command. The main difference is that update-sql
creates objects associated with undeployed changesets, and future-rollback-sql
drops objects associated with undeployed changesets.
Starting in Liquibase 4.4, there are changes in how you can configure Liquibase or how you can type commands, including future-rollback-sql
. The Liquibase CLI functionality aims to be backward compatible with all previous versions. However, it is best practice to follow the syntax rules on the Working with Command Parameters page and in the output of the --help
command.
Running the future-rollback-sql
command
To run the future-rollback-sql
command, specify the driver, classpath, and URL in the Liquibase properties file. For more information, see Specifying Properties in a Connection Profile. You can also specify these properties in your command line.
Then run the future-rollback-sql
command:
liquibase future-rollback-sql --changelog-file=sample.changelog.xml --output-file=future.txt
Note: Enter the name of the changelog and output you want to use in place of sample.changelog.xml
and future.txt
.
future-rollback-sql
command attributes
Tip: All commands and parameters use the --kebab-case
format in the CLI environment. This is the format Liquibase recommends for best results. If your preference is camelCase, it will still work in the CLI.
Attribute | Definition | Requirement |
---|---|---|
--changelog-file * |
Specifies the root changelog | Required |
--url
|
Specifies the JDBC database connection URL | Required |
--username
|
Specifies the database username | Required |
--password
|
Specifies the database password | Required |
--output-file ** |
Specifies the file path to where the rollback SQL will be written | Optional |
* Liquibase checks the changelog and any nested changelogs for the definitions of the changesets to roll back.
** If not specified, the future-rollback-sql
output goes to STDOUT
.
Note: The username
and password
attributes are not required for connections and systems which use alternate means of authentication.
future-rollback-sql
example output
When successful, the future-rollback-sql
command produces the following output:
-- *********************************************************************
-- SQL to roll back currently unexecuted changes
-- *********************************************************************
-- Change Log: example-changelog.sql
-- Ran at: 5/12/22, 10:34 AM
-- Against: DBUSER@jdbc:h2:tcp://localhost:9090/mem:dev
-- Liquibase version: 4.9.1
-- *********************************************************************
-- Lock Database
UPDATE PUBLIC.DATABASECHANGELOGLOCK SET LOCKED = TRUE, LOCKEDBY = 'DESKTOP-SQVSSV2 (192.168.1.179)', LOCKGRANTED = NOW() WHERE ID = 1 AND LOCKED = FALSE;
-- Release Database Lock
UPDATE PUBLIC.DATABASECHANGELOGLOCK SET LOCKED = FALSE, LOCKEDBY = NULL, LOCKGRANTED = NULL WHERE ID = 1;