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

How do I conditionally add a primary key to a database table using Liquibase?

我需要制作一个 Liquibase 迁移脚本,将主键添加到数据库 table 仅当该主键尚未添加时。执行此操作的最佳方法是什么?它将是这样的:

<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>

答案是...

<preConditions onFail="MARK_RAN">
  <not>
    <primaryKeyExists tableName="foo" />
  </not>
</preConditions>