Rollback Commands
The purpose of rollback commands is to revert deployed database changes. Rollback commands undo changes that have been deployed to a specified point such as a date, number of changes, or by tag name. When database changes are rolled back, the row associated with that change is deleted from the DATABASECHANGELOG table.
Note: In Liquibase 4.27.0 and later, you can enable the DATABASECHANGELOGHISTORY table to see a full history of rollbacks and other changes to your database.
Risks
Because data is constantly changing, there is a risk of data loss when a rollback is executed. There is also a risk of database drift if the rollback is not executed in all impacted database environments. Refer to the Blogs and Articles section for more information.
Rollback Category
These commands are available in all Liquibase editions.
rollback
: use this to revert changes made to the database based on a specified tag such as a release.rollback-sql
: run this before therollback
command to inspect the raw SQL for potential issues.rollback-to-date
: use this to revert changes made to the database to a previous state based on a specified date and/or time.rollback-to-date-sql
: run this before therollback-to-date
command to inspect the raw SQL for potential issues.rollback-count
: use this to revert a specified number of changesets.rollback-count-sql
: run this before therollback-count
command to inspect the raw SQL for potential issues.future-rollback-sql
: use this to inspect the raw SQL before rolling back changes that have not been deployed but added to the changelog.future-rollback-from-tag-sql
: use this to inspect the raw SQL before rolling back changes that have not been deployed but added to the changelog up to a specified tag.future-rollback-count-sql
: use this to inspect the raw SQL before rolling back a specified number of changes that have not been deployed but added to the changelog.
Since rollback commands change the schema of a database, Liquibase provides SQL output commands that you can run beforehand. The SQL output commands let you inspect the SQL that Liquibase will generate when you run the rollback commands.
Additional Commands for Liquibase Pro
These commands require an active Liquibase Pro license:
rollback-one-changeset
: use this to revert a single change without impact to changes made before or after the targeted changerollback-one-changeset-sql
: run this before therollback-one-changeset
command to inspect the raw SQL for potential issues.rollback-one-update
: use this to revert all changes that were applied to the database related to a specific deploymentID.rollback-one-update-sql
: run this before therollback-one-update
command to inspect the raw SQL for potential issues.
Each individual rollback command page specifies the criteria for using the command successfully, including a list of required and optional command-specific arguments.
Rollback Command Requirements
All rollback commands require the following command arguments:
- The root changelog file is specified as
--changelog-file
. - The JDBC database connection URL is specified as
--url
.
Your database may also require the --username
and --password
arguments in Liquibase. However, the username and password are not required for connections and systems which use alternate means of authentication.
Troubleshooting
If Liquibase returns an error when you run a utility command, use the Liquibase --help
parameter to check the correct syntax of the command and the command-specific parameters you can use with it.
For example, in the CLI:
liquibase <command> --help
Related Content
Visit the Using JDBC URL in Liquibase documentation page to learn more about Liquibase database connection requirements.
Liquibase Resources
Liquibase Help
Visit the Liquibase Forum channel to ask questions, find answers from other Liquibase users, and learn about new Liquibase version releases.
Tutorials
Visit the Liquibase Rollback Workflow documentation page to learn more about validating rollbacks and creating rollback statements. This includes the topic Automatic and Custom Rollbacks, which reviews how automatic rollbacks work and when custom rollback statements are needed.
Liquibase University
- Fundamentals of Liquibase: this course includes, but is not limited to, an introduction to the
rollback
,rollback-count
, androllback-to-date
commands. - Liquibase Commands for Troubleshooting: this course includes, but is not limited to, lessons on validating rollbacks, auto-generated versus custom rollbacks, and the
future-rollback-sql
command.
Blogs and Articles
- Database Rollback or Fix Forward?: read the blog about the common approaches to database issues and why a fix forward may be the right approach for you.
- 5 Ways to Fix a Bad Database Change in Liquibase: read this tips and tricks blog on handling a bad database change that includes rollback scripts and the fix forward approach.
- Introducing Targeted Rollback for One Change: read the blog to learn more about this Liquibase Pro command.
- Introducing Targeted Rollback for One Update: read the blog to learn more about this Liquibase Pro command.