我正在调查使用Liquibase进行使用Oracle的新项目,我想知道如何确保我的changeSet足够强大,可以在没有人工干预的情况下从任何类型的故障中恢复.理想情况下,我会使用runInTransaction属性,这将允许DDL在失败时回滚,但Oracle会自动提交DDL.对于这种情况,文档建议:
因此,通常最好每个changeSet只进行一次更改,除非您希望将一组非自动提交更改应用为插入数据等事务.
每个changeSet有一个DDL可以减少出现问题的几率,但不会消除它们.如果DDL成功,但对DATABASECHANGELOG的更新失败,从我的测试中看来,Liquibase似乎卡住了,需要手动干预.
有必要在每一步使用前提条件来避免这个问题吗?这使得生成的changeSet非常冗长.这是Liquibase示例表定义之一:
<changeSet author="jsmith" id="1">
<createTable tableName="departments"
remarks="The departments of this company. Does not include geographical divisions.">
<column name="id" type="number(4,0)">
<constraints nullable="false" primaryKey="true"
primaryKeyName="DPT_PK"/>
</column>
<column name="dname" type="varchar2(14)"
remarks="The official department name as registered on the internal website."/>
</createTable>
<addUniqueConstraint constraintName="departments_uk1"
columnNames="dname" tableName="departments"/>
<createSequence sequenceName="departments_seq"/>
</changeSet>
Run Code Online (Sandbox Code Playgroud)
为了使这个幂等,我认为它必须改为如下:
<changeSet author="jsmith" id="1">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="departments" />
</not>
</preConditions>
<createTable tableName="departments"
remarks="The departments of this company. Does not include geographical divisions.">
<column name="id" type="number(4,0)" / column>
<column name="dname" type="varchar2(14)" …Run Code Online (Sandbox Code Playgroud)