如何使用 Liquibase 有条件地将主键添加到数据库表?

Mar*_*ark 5 liquibase

我需要制作一个 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>
Run Code Online (Sandbox Code Playgroud)

Mar*_*ark 8

答案是……

<preConditions onFail="MARK_RAN">
  <not>
    <primaryKeyExists tableName="foo" />
  </not>
</preConditions>
Run Code Online (Sandbox Code Playgroud)