rollback-count-sql
The rollback-count-sql
command is a helper command that allows you to inspect the SQL Liquibase will run while using the rollback-count command.
Uses
The rollback-count-sql
command is used when you want to inspect the raw SQL before running the rollback-count
command, so you can correct any issues that may arise before running the command. Liquibase uses the raw SQL to revert any changesets between the most recent and the value you specified.
Running the rollback-count-sql
command
Before running the rollback-count-sql
command, you can run the history command to see all your previously executed changes.
Note: rollback-countSQL
works from the bottom of the list towards the top. Also, unlike the rollback-count
command, there is no impact of this command. See the rollback-count
topic for more information.
To run the rollback-count-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 rollback-count-sql
command:
liquibase --changelog-file=mychangelog.postgresql.sql rollback-count-sql 1
Note: Enter the name of the changelog and value you want to use in place of mychangelog.postgresql.sql
and 1
.
rollback-count-sql
global attributes
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, rollback-count
SQL output goes to STDOUT
.
Note: The username
and password
attributes are not required for connections and systems which use alternate means of authentication.
rollback-count-sql
command attributes
Attribute | Definition | Requirement |
---|---|---|
--value
|
The integer indicating the number of changes you want to rollback | Required |

Liquibase Community 4.9.1 by Liquibase
-- *********************************************************************
-- Rollback 1 Change(s) Script
-- *********************************************************************
-- Change Log: example-changelog.sql
-- Ran at: 5/6/22, 12:03 PM
-- 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;
Liquibase command 'rollback-count-sql' was executed successfully.