【发布时间】:2018-03-10 12:57:43
【问题描述】:
我是 liquibase 的新手,并且使用 spring boot + liquibase 项目创建了一个示例表。我在文件“createSampleTable.xml”中创建表的初始更改日志:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.7"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.7
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.7.xsd">
<changeSet id="1" author="Russ">
<comment>A sample table to see if liquibase works</comment>
<createTable tableName="testy">
<column name="VALUE" type="varchar(32)"/>
</createTable>
<insert tableName="testy">
<column name="value" value="Hello, world!"/>
</insert>
<insert tableName="testy">
<column name="value" value="Riddikulus!"/>
</insert>
</changeSet>
</databaseChangeLog>
现在我已经验证了我的 liquibase 配置,同样的部署已经在我们的 2 个较低的区域(开发和测试)中运行,但我们还没有建立阶段或生产。我想“撤消”示例表并开始创建我真正的数据库结构。
我的理解是我有两个选择:条件drop table,rollback
我目前正在尝试实现条件删除表as the documentation states,但即使preconditions documentation 明确指出应识别onFail 注释,也无法识别建议的属性。这是我提出的解决方案的实现(这是“createSampleTable.xml”文件的当前内容:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.7"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.7
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.7.xsd">
<!-- The documentation for liquibase says if you ever create a changeset
in error that you never really wanted to follow this approach.
The general idea is to delete the original changeset and then
provide a new changeset that should only run if the original changset
has run as well. In essence this allows us to remove a naughty change
entirely from the code and prevent it from being run in new
environments while providing an "undo" changeset to be ran in
environments where this changeset has unfortunately already ran.
Documentation referenced and approach taken:
http://www.liquibase.org/2008/10/dealing-with-changing-changesets.html
To satisfy developer's curiosity and prevent them from having to
look up the history in the repository the original changeset of id=1
was simply to create a sample table to make sure the initial liquibase
config was working.
-->
<changeSet id="1-undo" author="Russ">
<preConditions onFail="MARK_RAN">
<changeSetExecuted id="1" author="Russ" changeLogFile="liquibase/createSampleTable.xml" />
</preConditions>
<dropTable tableName="testy"/>
</changeSet>
</databaseChangeLog>
但是,当同时运行 onFail 属性和
<changeSetExecuted> 标记无法被架构识别。在此之后,我尝试实现 maven 插件来回滚,但这会在构建时执行,所以这个目标只会解析一个区域。
普遍接受的撤消更改的方法是什么?如果您正在实施 Spring Boot liquibase 项目,该方法是否会有所不同?
【问题讨论】:
标签: java spring-boot liquibase undo changeset