2015-09-17 91 views
0

我需要制作一个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> 

回答

2

答案是...

<preConditions onFail="MARK_RAN"> 
    <not> 
    <primaryKeyExists tableName="foo" /> 
    </not> 
</preConditions> 
相关问题