Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liquibase - Rolling back a set of changesets

Tags:

liquibase

We do database releases which are made up of a group of change sets and our database change logs are organised in the following way

   MasterChangeLog.xml

           ---> Release0001.XML
                    ---> AddCustomerTable.XML
                    ---> AddOrderTable.XML

           ---> Release0002.XML
                    ---> AddNewColumnsToCustomerTable.XML
                    ---> AlterOrderTableXML

           ---> Release0003.XML
                    ---> AddPreferedCustomerTable.XML

I would like to know how I would go about rolling back a set of change sets. I was hoping that I could use tagDatabase with the release number (Release001, Release002 or Release003) and just roll back using the tag

I would expect to be able to do something like this if I wanted to rollback all change to Release001

java -jar "liquibase.jar" --changeLogFile="MasterChangeLog.xml" Rollback "Release0002"

Could you please tell me how I would go about getting this to work with Liquibase?

Thanks

like image 886
Nicholas Hammond Avatar asked Nov 03 '10 09:11

Nicholas Hammond


People also ask

How do I roll back Liquibase changes?

Running the rollback command To run the rollback 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.

How do you roll back a changeset?

To roll back a changeset from Source Control ExplorerIn Source Control Explorer, select an item, open its shortcut menu, and choose Rollback. The items you select determine the scope that the rollback changes.

How do I roll back Liquibase in spring boot?

To roll back any changes, create the liquibase. rollback-file file in Spring Boot and generate a rollback script for changes associated with changesets: -- rollback drop table test_table; Note: You can also use tags for the rollback.


1 Answers

The command you listed is valid if Release002 is a valid tag. You probably don't want/need quotes around the Release0002 tag, though.

When rolling back using a tag, liquibase will start at the end of your executed changesets and roll back each in reverse order until it gets to the changeset that was tagged before. I am not sure from your description if that is what you want.

In your example, if you tagged the database after Realease002.xml ran, running "rollback Release0002" would roll back everything in Release0003. If you wanted to rollback everything in Release0002 you would need to run "rollback Release0001" or make the Release0002 tag before executing the Release0002 changesets. Either way, however, you will have Release0003 rolled back because it came after Release0002.

The reason liquibase does not support picking and choosing changeSets to roll back is because there is often dependencies between changesets because they often build upon each other, and so rolling back an arbitrary group of changesets in the middle often has unexpected consequences.

like image 153
Nathan Voxland Avatar answered Nov 20 '22 17:11

Nathan Voxland