为了使数据库部署自动化,并围绕数据库更改获得一些结构,我正在试用Liquibase。
这是我的Changeset,我想对它进行自动回滚评估。现在,我试图在foreign key constraint中引入一个错误,并期望rollback statements在错误之后运行,并从customer表中删除列。
">http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
<preConditions>
<dbms type="mysql" />
</preConditions>
<changeSet id="002" author="Hrishi" failOnError="true"
runInTransaction="true">
<preConditions onError="HALT" onFail="HALT"
onFailMessage="The table gender doesnt exist. Precondition not met.">
<not>
<columnExists tableName="customer" columnName="gender_id" />
</not>
<and>
<not>
<foreignKeyConstraintExists foreignKeyName="fk_gender_customer"/>
</not>
</and>
</preConditions>
<addColumn tableName="customer" schemaName="sakila">
<column name="gender_id" type="smallint(1)" />
</addColumn>
<addForeignKeyConstraint constraintName="fk_gender_customer"
referencedTableName="gender" baseColumnNames="gender_id"
baseTableName="customer" referencedColumnNames="invoking_an_error" />
<rollback>
<dropColumn tableName="customer" columnName="gender_id" />
<dropForeignKeyConstraint baseTableName="customer"
constraintName="fk_gender_customer" />
</rollback>
</changeSet>然而,真正发生的是DATABASECHANGELOG表中没有条目。但customer表中的列仍然存在。我看过关于液化库文档的addColumn url的帮助,支持MySQL。
column.html
我的理解是正确的吗?它应该自动回溯变化集中的所有语句吗?
编辑:我认为这种特殊情况下的问题是ALTER语句。来自MySQL 不能回滚的文档。
发布于 2016-02-17 17:10:54
我不确定您发出的命令,但是当发生错误时,变更集中的<rollback>部分中列出的更改不会自动发生。当发生错误时,液化库试图回滚数据库事务,但是如果已经提交了一些内容,则可以进入不一致的状态。<rollback>标记在那里,这样您就可以使用液化基rollback命令手动回滚更改。
https://stackoverflow.com/questions/35461896
复制相似问题