Maven rollbackSQL
rollbackSQL
is a helper command that produces the raw SQL Liquibase would run when using the Maven rollback goal with the liquibase.rollbackCount
, liquibase.rollbackTag
, or liquibase.rollbackDate
attributes:
liquibase.rollbackCount
– Liquibase uses the raw SQL to revert any changesets between the most recent and the value you specifiedliquibase.rollbackTag
– Liquibase uses the raw SQL to revert all changes that were made to the database after the specified tagliquibase.rollbackDate
– Liquibase uses the raw SQL to revert all changes made to your database from today's date to the date and time you specify
Uses
rollbackSQL
is typically used to inspect the SQL Liquibase uses to revert changes associated with a tag, date, or depending on the number you specify when you run the rollback
goal. It is best practice to use the rollbackSQL
goal before running the rollback
command to correct any issues that may arise before running the goal and avoid any potential risks.
Maven configuration
You can configure Liquibase Maven in multiple ways. You can pass arguments like <changeLogFile>
in Maven directly in your pom.xml
file, in a liquibase.properties
file referenced in your POM, as environment variables, or as JVM system properties.
Tip: For more information about the Maven configuration, see Configuring Maven.
You may want to add <migrationSqlOutputFile>specify your output file here</migrationSqlOutputFile>
to your pom.xml
or specify it in another valid way. This argument defines the file to output the rollback SQL script.
Running the rollbackSQL
Maven goal
Running the rollbackSQL
goal requires a Maven project to be implemented. Also, before running the rollbackSQL
goal, you can run the Maven history goal to see all your previously executed changes.
Running the rollbackSQL
Maven goal with the rollbackCount
attribute
- To run the
rollbackSQL
goal with theliquibase.rollbackCount
attribute, type the following in your command prompt:
mvn liquibase:rollbackSQL -Dliquibase.rollbackCount=2
Note: Enter the value you want to use in place of 2
.
liquibase.rollbackCount
attribute
-- *********************************************************************
--rollback 2 Change(s) Script
-- *********************************************************************
-- Change Log: dbchangelog.xml
-- Ran at: 11/30/20 5:06 AM
-- Against: MVN_UAT@jdbc:oracle:thin:@localhost:1521/ORCL
-- Liquibase version: 4.1.1
-- *********************************************************************
-- Lock Database
UPDATE DATABASECHANGELOGLOCK SET LOCKED = 1, LOCKEDBY = 'WIN-20E107KB4TN (172.30.3.88)', LOCKGRANTED = TO_TIMESTAMP('2020-11-30 05:06:25.27', 'YYYY-MM-DD HH24:MI:SS.FF') WHERE ID = 1 AND LOCKED = 0;
-- Rolling Back ChangeSet: dbchangelog.xml::1606322157619-24::Nataliya
DROP TABLE "36";
DELETE FROM DATABASECHANGELOG WHERE ID = '1606322157619-24' AND AUTHOR = 'Nataliya' AND FILENAME = 'dbchangelog.xml';
-- Rolling Back ChangeSet: dbchangelog.xml::1606322157619-22::Nataliya
DROP TABLE "35";
DELETE FROM DATABASECHANGELOG WHERE ID = '1606322157619-22' AND AUTHOR = 'Nataliya' AND FILENAME = 'dbchangelog.xml';
-- Release Database Lock
UPDATE DATABASECHANGELOGLOCK SET LOCKED = 0, LOCKEDBY = NULL, LOCKGRANTED = NULL WHERE ID = 1;
Running the rollbackSQL
Maven goal with the rollbackTag
attribute
- To run the
rollbackSQL
goal with theliquibase.rollbackTag
attribute, type the following in your command prompt:
mvn liquibase:rollbackSQL -Dliquibase.rollbackTag=version1
Note: Enter the name of the tag you want to use in place of version1
. Alternatively, you can specify two properties in your pom.xml
file under the <properties></properties>
in the <project></project>
level:
<liquibase.tag>v3.2.1</liquibase.tag>
<liquibase.rollbackTag>${liquibase.tag}</liquibase.rollbackTag>
liquibase.rollbackTag
attribute
-- *********************************************************************
--rollback to 'version1' Script
-- *********************************************************************
-- Change Log: dbchangelog.xml
-- Ran at: 11/30/20 5:01 AM
-- Against: MVN_UAT@jdbc:oracle:thin:@localhost:1521/ORCL
-- Liquibase version: 4.1.1
-- *********************************************************************
-- Lock Database
UPDATE DATABASECHANGELOGLOCK SET LOCKED = 1, LOCKEDBY = 'WIN-20E107KB4TN (172.30.3.88)', LOCKGRANTED = TO_TIMESTAMP('2020-11-30 05:01:01.512', 'YYYY-MM-DD HH24:MI:SS.FF') WHERE ID = 1 AND LOCKED = 0;
-- Rolling Back ChangeSet: dbchangelog.xml::1606322157619-24::Nataliya
DROP TABLE "36";
DELETE FROM DATABASECHANGELOG WHERE ID = '1606322157619-24' AND AUTHOR = 'Nataliya' AND FILENAME = 'dbchangelog.xml';
-- Rolling Back ChangeSet: dbchangelog.xml::1606322157619-22::Nataliya
DROP TABLE "35";
DELETE FROM DATABASECHANGELOG WHERE ID = '1606322157619-22' AND AUTHOR = 'Nataliya' AND FILENAME = 'dbchangelog.xml';
-- Release Database Lock
UPDATE DATABASECHANGELOGLOCK SET LOCKED = 0, LOCKEDBY = NULL, LOCKGRANTED = NULL WHERE ID = 1;
Running the rollbackSQL
Maven goal with the rollbackDate
attribute
- To run the
rollbackSQL
goal with theliquibase.rollbackDate
attribute, type the following in your command prompt:
mvn liquibase:rollbackSQL -Dliquibase.rollbackDate=2020-11-30
Note: Enter the date you want to use in place of 2020-11-30
. There are several ways to revert your changes with the liquibase.rollback-to-date
attribute. You can use YYYY-MM-DD HH:MM:SS
or YYYY-MM-DD'T'HH:MM:SS
formats to specify both date and time. Also, you can specify date or time only.
liquibase.rollbackDate
attribute
-- *********************************************************************
--rollback to 2020-11-30 Script
-- *********************************************************************
-- Change Log: dbchangelog.xml
-- Ran at: 11/30/20 5:08 AM
-- Against: MVN_UAT@jdbc:oracle:thin:@localhost:1521/ORCL
-- Liquibase version: 4.1.1
-- *********************************************************************
-- Lock Database
UPDATE DATABASECHANGELOGLOCK SET LOCKED = 1, LOCKEDBY = 'WIN-20E107KB4TN (172.30.3.88)', LOCKGRANTED = TO_TIMESTAMP('2020-11-30 05:08:38.504', 'YYYY-MM-DD HH24:MI:SS.FF') WHERE ID = 1 AND LOCKED = 0;
-- Rolling Back ChangeSet: dbchangelog.xml::1606322157619-24::Nataliya
DROP TABLE "36";
DELETE FROM DATABASECHANGELOG WHERE ID = '1606322157619-24' AND AUTHOR = 'Nataliya' AND FILENAME = 'dbchangelog.xml';
-- Rolling Back ChangeSet: dbchangelog.xml::1606322157619-22::Nataliya
DROP TABLE "35";
DELETE FROM DATABASECHANGELOG WHERE ID = '1606322157619-22' AND AUTHOR = 'Nataliya' AND FILENAME = 'dbchangelog.xml';
-- Rolling Back ChangeSet: dbchangelog.xml::1606322157619-20::Nataliya
DROP TABLE "24";
DELETE FROM DATABASECHANGELOG WHERE ID = '1606322157619-20' AND AUTHOR = 'Nataliya' AND FILENAME = 'dbchangelog.xml';
-- Rolling Back ChangeSet: dbchangelog.xml::1606322157619-19::Nataliya
DROP TABLE "34";
DELETE FROM DATABASECHANGELOG WHERE ID = '1606322157619-19' AND AUTHOR = 'Nataliya' AND FILENAME = 'dbchangelog.xml';
-- Rolling Back ChangeSet: dbchangelog.xml::1606322157619-18::Nataliya
DROP TABLE "25";
DELETE FROM DATABASECHANGELOG WHERE ID = '1606322157619-18' AND AUTHOR = 'Nataliya' AND FILENAME = 'dbchangelog.xml';
-- Rolling Back ChangeSet: dbchangelog.xml::1606322157619-17::Nataliya (generated)
DROP TABLE TEST24;
DELETE FROM DATABASECHANGELOG WHERE ID = '1606322157619-17' AND AUTHOR = 'Nataliya (generated)' AND FILENAME = 'dbchangelog.xml';
-- Release Database Lock
UPDATE DATABASECHANGELOGLOCK SET LOCKED = 0, LOCKEDBY = NULL, LOCKGRANTED = NULL WHERE ID = 1;
rollbackSQL
required Maven configuration attributes
Attribute | Definition |
---|---|
liquibase.rollbackCount
|
Defines the number of changesets to roll back. Default value is: 1. |
liquibase.rollbackDate
|
Defines the date for which you want to roll back the database. The format of the date must match either an ISO date format or that of the |
liquibase.rollbackTag
|
Defines the tag for which you want to roll back the database. |
rollbackSQL
optional Maven configuration attributes
Attribute | Definition |
---|---|
liquibase.changeLogDirectory
|
Specifies the path to the directory where Liquibase can find your changelog file. |
liquibase.changeLogFile
|
The changelog file for Liquibase to use. |
liquibase.changelogCatalogName
|
Specifies the catalog Liquibase will use to create your changelog tables. |
liquibase.changelogSchemaName
|
Specifies the schema Liquibase will use to create your changelog tables. |
liquibase.clearCheckSums
|
Boolean. Forces checksums to be cleared from the DATABASECHANGELOG table. Default value is: false. |
liquibase.contexts
|
Specifies which contexts Liquibase will execute, which can be separated by a comma if multiple contexts are required. If a context is not specified, then all contexts will be executed. |
liquibase.databaseChangeLogLockTableName
|
Specifies the table name to use for the DATABASECHANGELOGLOCK table. |
liquibase.databaseChangeLogTableName
|
Specifies the table name to use for the DATABASECHANGELOG table. |
liquibase.databaseClass
|
Specifies the database object class. |
liquibase.defaultCatalogName
|
Specifies the default catalog name to use for the database connection. |
liquibase.defaultSchemaName
|
Specifies the default schema name to use for the database connection. |
liquibase.driver
|
Specifies the driver class name to use for the database connection. |
driverPropertiesFile
|
Specifies the location of a JDBC connection properties file which contains properties the driver will use. |
liquibase.emptyPassword
|
Deprecated. Boolean. Use an empty or null value for the password instead. Default value is: false. |
expressionVariables
|
Specifies a map-based collection of changelog properties to apply. |
expressionVars
|
Specifies a property-based collection of changelog properties to apply. |
liquibase.includeArtifact
|
Boolean. Includes a Maven project artifact in the class loader, which obtains the Liquibase properties file and changelog files. Default value is |
liquibase.includeTestOutputDirectory
|
Boolean. Includes the Maven test output directory in the class loader which obtains the Liquibase properties file and changelog files. Default value is |
liquibase.labels
|
Specifies which labels Liquibase runs, and which can be separated by a comma if multiple labels are required or you need to designate a more complex expression. If no label is specified, then all labels are run. |
liquibase.licenseKey
|
Specifies your Liquibase Pro license key. |
liquibase.migrationSqlOutputFile
|
Specifies the file to output the rollback/migration SQL script to. If it exists, it will be overwritten. Default value is: |
liquibase.outputDefaultCatalog
|
Boolean. Specifies whether to ignore the catalog or database name. Default value is: false. |
liquibase.outputDefaultSchema
|
Boolean. Specifies whether to ignore the schema name. Default value is: false. |
liquibase.outputFileEncoding
|
Indicates that you want to set the character encoding of the output file during the |
liquibase.password
|
Specifies the database password for the database connection. |
liquibase.promptOnNonLocalDatabase
|
Deprecated. Boolean. Controls whether users are prompted before executing changesets to a non-local database. Default value is: true. |
liquibase.propertyFile
|
Specifies the Liquibase properties file to use for configuration, like |
liquibase.propertyFileWillOverride
|
Boolean. Indicates that you want the |
liquibase.propertyProviderClass
|
Specifies the property provider, which must be a |
liquibase.server
|
Specifies the server ID in the Maven |
liquibase.skip
|
Boolean. Specifies whether to skip running Liquibase. The use of this attribute is not recommended but can be used when needed. Default value is: false. |
systemProperties
|
Specifies a list of system properties you want to pass to the database. |
liquibase.url
|
Specifies the database URL you want to use to execute Liquibase. |
liquibase.username
|
Specifies the database username for the database connection. |
liquibase.verbose
|
Boolean. Controls the amount of output detail when you call the plugin. Default value is: false. |