How to tag a changeset in liquibase to rollback

匿名 (未验证) 提交于 2019-12-03 00:48:01

问题:

I have configured the maven pluggin for liquibase as specified in maven configuration.
Now created a changeset like :-

Created the sql to update DB using command line :- mvn liquibase:updateSQL

But just want to know how to rollback using a "rollbackTag" parameter. i.e. If run the command "mvn liquibase:rollbackSQL", what should be the value of "rollbackTag" parameter.

And is it possible to rollback using the changeset id ?

回答1:

Rollback tags are designed to checkpoint your database's configuration.

The following commands will roll the database configuration back by 3 changesets and create a tag called "checkpoint":

mvn liquibase:rollback -Dliquibase.rollbackCount=3 mvn liquibase:tag -Dliquibase.tag=checkpoint 

You can now update the database, and at any stage rollback to that point using the rollback tag:

mvn liquibase:rollback -Dliquibase.rollbackTag=checkpoint 

or alternatively generate the rollback SQL:

mvn liquibase:rollbackSQL -Dliquibase.rollbackTag=checkpoint 

Revised example

I initially found it difficult to figure out how to configure the liquibase Maven plugin. Just in case it helps here's the example I've used.

The liquibase update is configured to run automatically, followed by tagging the database at the current Maven revision number.

4.0.0com.myspotontheweb.dbliquibase-demo1.0-SNAPSHOTjdbc:h2:target/db1/liquibaseTest;AUTO_SERVER=TRUEorg.h2.Driveruserpasscom/myspotontheweb/db/changelog/db-changelog-master.xmlfalsecom.h2databaseh21.3.162dbupdatetrueorg.liquibaseliquibase-maven-plugin2.0.2process-resources${project.version}updatetag

Liquibase is now configured as part of the standard life-cycle so can be run as follows:

mvn clean compile 


回答2:

I personally prefer to put the tag as part of the changeset files, so if you have to rollback or delete all the records in the DATABASECHANGELOG you won't loose your tagging records.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!