我需要制作一个Liquibase迁移脚本,只有在尚未添加主键的情况下才将主键添加到数据库表中。这样做的最佳方法是什么?它会是这样的:
<changeSet id="...">
<preConditions>
(What goes here? Should I use <sqlCheck>, or is there a better alternative?)
</preConditions>
<addPrimaryKey tableName="foo" columnNames="bar" constraintName="foo_pk" />
</changeSet>
答案 0 :(得分:2)
答案是......
<preConditions onFail="MARK_RAN">
<not>
<primaryKeyExists tableName="foo" />
</not>
</preConditions>