rollback <tag> command

The rollback <tag> command will roll back changes made to the database based on the specified tag.

Description

Liquibase allows for reverting changes to the database through rollback commands. The rollback <tag> command will revert all changes that were made to the database after the specified tag.

  • If the tag name is unknown, it can be found in the DATABASECHANGELOG table.
  • When you run a rollback <tag>, Liquibase will roll back sequentially all the deployed changes until it reaches the tag row in the DATABASECHANGELOG table.
  • Change Types such as dropTable and insert have no corresponding rollback commands that can be automatically generated.

Uses

The rollback <tag> command is typically used 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, you have to rollback to release 3 first.

  • Use an empty tag when you do not want to undo changes in rollback mode.
  • When you want to override the default generated rollback commands, specify the rollback commands using the tag within the changeset tag

rollback <tag> global attributes

Attribute Definition Requirement
--changeLogFile* The root changelog Required
--url The JDBC database connection URL Required
--username The database username Required
--password The database password Required

Impact of running the rollback <tag> command

Using the rollback <tag> command comes with risks to your database, so it's important to look for potential unintended consequences before executing this command.

It is a best practice to run the rollbackSQL <tag> command that allows you to inspect for potential mistakes before running the command.

Running the rollback <tag> command

Before using the rollback commands, verify your liquibase.properties file includes the driver class path, database URL, and user authentication information.

If you have not set any tags, run liquibase tag mytagname to specify a tag name for your releases.

Using CLI

liquibase [global params] rollback [your tag name]

liquibase --changeLogFile=postgres_lbpro_master_changelog.xml tag v3.2.1

Using Maven

To use the Maven rollback command, you need to specify two properties in your pom.xml file, run:

<liquibase.tag>v3.2.1</liquibase.tag>

and

<liquibase.rollbackTag>${liquibase.tag}</liquibase.rollbackTag>

Then run the rollback mvn compile liquibase:rollback

Using Ant

Create a build script with your defined tasks and call the Liquibase tag function.

<target name="tag" depends="prepare">
	<tagDatabase
		changeLogFile="${changelogLogFile}"
		url="${url}"
		username="${username}"
		password="${password}"
		promptOnNonLocalDatabase="false"
		classpathref="classpath"
		tag="ant-tag">
	</tagDatabase>
</target>