回滚标签旨在检查您的数据库配置。
以下命令将数据库配置回滚 3 个变更集并创建一个名为“检查点”的标记:
mvn liquibase:rollback -Dliquibase.rollbackCount=3
mvn liquibase:tag -Dliquibase.tag=checkpoint
您现在可以更新数据库,并在任何阶段使用回滚标签回滚到该点:
mvn liquibase:rollback -Dliquibase.rollbackTag=checkpoint
或者生成回滚 SQL:
mvn liquibase:rollbackSQL -Dliquibase.rollbackTag=checkpoint
修改示例
我最初发现很难弄清楚如何配置 liquibase Maven 插件。以防万一,这是我使用的示例。
liquibase 更新配置为自动运行,然后将数据库标记为当前 Maven 修订号。
<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 现在配置为标准生命周期的一部分,因此可以按如下方式运行:
mvn clean compile