如何标记liquibase中的变更集以进行回滚 [英] How to tag a changeset in liquibase to rollback

查看:1370
本文介绍了如何标记liquibase中的变更集以进行回滚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照 maven配置中的指定配置liquibase的maven插件。

现在创建了一个变更集,如: -

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

<changeSet id="changeRollback" author="nvoxland">
            <createTable tableName="changeRollback1">
                <column name="id" type="int"/>
            </createTable>
            <rollback>
                <dropTable tableName="changeRollback1"/>
            </rollback>
    </changeSet>

使用命令行创建sql以更新DB: -
mvn liquibase: updateSQL

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

但是只想知道如何使用rollbackTag参数回滚。
ie如果运行命令 mvn liquibase:rollbackSQL ,应该是rollbackTag参数的值。

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.

是否可以使用更改集ID回滚?

And is it possible to rollback using the changeset id ?

推荐答案

回滚标记设计用于检查数据库配置。

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

以下命令将数据库配置回滚3个变更集,并创建一个名为checkpoint的标签:

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

或者生成回滚SQL: p>

or alternatively generate the rollback SQL:

mvn liquibase:rollbackSQL -Dliquibase.rollbackTag=checkpoint



修订示例



我最初发现很难弄清如何配置liquibase Maven插件。以防万一它帮助这里的例子,我使用。

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.

liquibase更新配置为自动运行,然后以当前Maven修订版本号标记数据库。

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

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.myspotontheweb.db</groupId>
    <artifactId>liquibase-demo</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <!-- Liquibase settings -->
        <liquibase.url>jdbc:h2:target/db1/liquibaseTest;AUTO_SERVER=TRUE</liquibase.url>
        <liquibase.driver>org.h2.Driver</liquibase.driver>
        <liquibase.username>user</liquibase.username>
        <liquibase.password>pass</liquibase.password>
        <liquibase.changeLogFile>com/myspotontheweb/db/changelog/db-changelog-master.xml</liquibase.changeLogFile>
        <liquibase.promptOnNonLocalDatabase>false</liquibase.promptOnNonLocalDatabase>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.3.162</version>
        </dependency>
    </dependencies>
    <profiles>
        <profile>
            <id>dbupdate</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.liquibase</groupId>
                        <artifactId>liquibase-maven-plugin</artifactId>
                        <version>2.0.2</version>
                        <executions>
                            <execution>
                                <phase>process-resources</phase>
                                <configuration>
                                    <tag>${project.version}</tag>
                                </configuration>
                                <goals>
                                    <goal>update</goal>
                                    <goal>tag</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

Liquibase现在配置为标准生命周期的一部分,因此可以运行如下: p>

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

mvn clean compile

这篇关于如何标记liquibase中的变更集以进行回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆