rollback-one-changeset

Note: This is a Liquibase Pro command, so you need a Liquibase Pro License Key to use it.


The rollback-one-changeset command reverts (rolls back) one non-sequential changeset made during a previous change to your database. It is only available for Liquibase Pro users.

Uses

The rollback-one-changeset command is typically used when you want to undo a change made to your database and revert it to a previous state without affecting any other changes made to your database.

While the rollback command reverts all changesets deployed sequentially to a specified point by using rollbackDate, rollback-count, or rollback <tag_name>, the rollback-one-changeset command allows you to target a specific changeset without impacting changesets that came before or after it.

The image above shows changesets A through I, with changeset I being the most recently deployed. As you can see, the rollback-one-changeset command allows you to target changeset B and revert it to its previous state without impacting the others.

Impacts of rollback-one-changeset

Like any targeted tool, using the rollback-one-changeset command comes with risks of unintended consequences. Because of this, the command requires a --force flag to indicate that you intend to run it.

Warning: Look for potential unintended consequences before using this command.

It is a best practice to run the rollback-one-changeset-sql command because it allows you to inspect the rollback SQL and search for any potential mistakes before you execute rollback-one-changeset.

Running the rollback-one-changeset command

Before running the rollback-one-changeset command, gather the following information from your DATABASECHANGELOG table or by running the history command:

  • The author of the changeset you want to revert
  • The ID of the changeset you want to revert
  • The file name (changeset path) of the changeset you want to revert

Note: The --rollbackScript attribute is only needed if the rollback is not already defined in the changelog, and if it is not a rollback that is automatically provided by Liquibase.

Then run the rollback-one-changeset command, with your information:

liquibase --changelog-file=changelog.xml rollback-one-changeset --changeset-author="LiquibaseProUser" --changeset-id="createProc-proschema" --changeset-path=changelog.xml --force

For more command specific help, type liquibase rollback-one-changeset --help into the command prompt.

rollback-one-changeset global attributes

Tip: For best results, specify all commands and parameters in the --kebab-case format in the CLI. If your preference is camelCase, it also works in the CLI.

Parameter Definition Requirement
--changelog-file

The root changelog

Required
--url

The JDBC database connection URL

Required
--username

The database username

Required
--password

The database password

Required
--liquibaseProLicenseKey

Your Liquibase Pro license key

Required

Note: The username and password attributes are not required for connections and systems which use alternate means of authentication.

rollback-one-changeset command attributes

Parameter Definition Requirement
--changeset-id

The changeset ID from the changelog.

Required
--changeset-author

The name of the author for the changeset.

Required
--changeset-path

The path to the changelog containing the changeset you want to roll back.

Required
--force

A required parameter which indicates you intend to use this feature.

Required
--rollback-script

The path to the script to use to perform the rollback.

Optional *

* This option is only needed if the rollback is not already defined in the changelog, and if it is not a rollback that is automatically provided by Liquibase.

Output

When successful, the rollback-one-changeset command produces the following output:

Liquibase Version: 4.9.1
Liquibase Pro 4.9.1 by Liquibase licensed to Liquibase Pro Evaluation until Tue Jun 07 18:00:00 MDT 2022
WARNING!  Your license will expire in 29 days!
To renew Liquibase Pro please contact sales@liquibase.com or go to https://www.liquibase.org/download
Rolling Back Changeset: example-changelog.sql::2::your.name

----------------------------------------------------------------------
View a report of this operation at https://hub.liquibase.com/r/eOlOgfwZ90
* IMPORTANT: New users of Hub first need to Sign In to your account
with the one-time password sent to your email, which also serves as
your username.
----------------------------------------------------------------------

rollback-one-changeset executed for DBUSER@jdbc:h2:tcp://localhost:9090/mem:dev
Liquibase command 'rollback-one-changeset' was executed successfully.

Like what you see? Try this command in Pro for Free.

Related links