rollback

The rollback command rolls back changes made to the database based on the specified tag.

Uses

The rollback command is typically used to revert all changes that were made to the database after the tag you specify.

When you run rollback, Liquibase will roll back sequentially all the deployed changes until it reaches the tag row in the DATABASECHANGELOG table. For example, you can use the rollback command when you want to undo a series of changes made to your database related to a specific tag such as a numbered release. If you have tags for release 1, release 2, and release 3, and need to make a correction in release 2, the rollback command will rollback release 3 first.

The following image shows that if we deploy the createTable C changeset and run the rollback --tag=version1 command to revert changes, Liquibase will roll back only createTable C value:

Impact

Using the rollback command comes with risks to your database, so it's important to look for potential unintended consequences before executing this command. You can do this with the rollback-sql command.

Syntax

To run the rollback command, specify the driver, classpath, and URL in the Liquibase properties file. For more information, see Create and Configure a liquibase.properties File. You can also specify these properties in your command line.

Also, before running the rollback command, you need to know the following:

  • If the tag name is unknown to you, you can find it in the DATABASECHANGELOG table.
  • If you don't have any tags specified, you can run the tag command. If you run the tag command to mark the current database state or release, your tag will be applied to the last row in the DATABASECHANGELOG table.
  • If you use the tagDatabase Change Type to create a tag changeset in the changelog file and want to roll back changes applied after this tag, the rollback command will remove all changes made after this tag row and the tag row.
  • If you run the tag command, deploy changesets, and then add the tagDatabase Change Type in your changelog file, your changes and the tag row created by the tagDatabase Change Type will be removed till the command reaches the tag specified with the rollback command.
liquibase rollback --tag=myTag --changelog-file=example-changelog.xml

Note: The --tag=myTag syntax was added in Liquibase 4.4. If you use an older version, specify your tag as a positional argument: <command> myTag.

Command arguments

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.

Attribute Definition Requirement
--changelog-file

The root changelog

Required
--tag

The tag identifying which tagged changesets in the changelog to evaluate. Specify as --tag=myTag. Positional format <command> <tag> deprecated in 4.4+.

Required
--url

The JDBC database connection URL. See Using JDBC URL in Liquibase.

Required
--change-exec-listener-class

Fully-qualified class which specifies a ChangeExecListener. For more information, see Implementing a Custom ChangeExecListener Class with Liquibase and ChangeExecListenerCommandStep.

Optional
--change-exec-listener-properties-file

Path to a properties file for the ChangeExecListener class. For more information, see Implementing a Custom ChangeExecListener Class with Liquibase and ChangeExecListenerCommandStep.

Optional
--context-filter

Specifies the changeset contexts to match. Contexts are tags you can add to changesets to control which changesets are executed in any particular migration run.

Note: If you use Liquibase 4.23.0 or earlier, use the syntax --contexts instead of --context-filter.

Optional
--default-catalog-name

Name of the default catalog to use for the database connection

Optional
--default-schema-name

Name of the default schema to use for the database connection. If defaultSchemaName is set, then objects do not have to be fully qualified. This means you can refer to just mytable instead of myschema.mytable.

Tip: In Liquibase v4.23.0+, camelCase for defaultSchemaName works successfully. If you are on an earlier version, camelCase may not work as expected.

Note: The syntax liquibase.command.defaultSchemaName is valid for v4.19.0+. For prior versions, use defaultSchemaName.

Optional
--driver

The JDBC driver class

Optional
--driver-properties-file

The JDBC driver properties file

Optional
--label-filter

Specifies the changeset labels to match. Labels are tags you can add to changesets to control which changesets will be executed in any migration run.

Optional
--password

Password to connect to the target database.

Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro.

Optional
--rollback-script

The path to the script to use to perform the rollback. Only needed if the rollback is not already defined in the changelog, and if it is not a rollback statement that is automatically generated by Liquibase.

Optional
--tag-version

Tag version to use for multiple occurrences of a tag. Valid values are NEWEST and OLDEST. If set to NEWEST, Liquibase rolls back changes up to the most recent instance of the tag. Any older instances of the tag remain in the DATABASECHANGELOG table. If set to OLDEST, Liquibase rolls back changes up to the first instance of the tag. Default: OLDEST

Optional
--username

Username to connect to the target database.

Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro.

Optional

Note: The username and password attributes are not required for connections and systems which use alternate means of authentication. Also, you can specify database credentials as part of the url attribute.

Related links