3

I have currently an issue with liquibase preconditions. I would like to insert something only if a precondition request does'nt answer 0 or null... I explain :

<changeSet id="myId" author="myName">
<preConditions onFail="MARK_RAN">
    <sqlCheck expectedResult=????>SELECT COUNT(1) FROM tableB WHERE column2 IS NOT NULL;
    </sqlCheck>
</preConditions>
<insert tableName="tableA">
    <column name="column1" valueComputed="(SELECT columnA FROM tableB WHERE columnB IS NOT NULL;)" />
    <column name="column2" valueComputed="(SELECT columnB FROM tableB WHERE columnB IS NOT NULL;)" />
</insert>

I would like for my changeSet to only be played if the first request give me a result. Is there a way to do that without a custom precondition ?

Thanks in advance

Sophie3591
  • 51
  • 1
  • 1
  • 3

1 Answers1

11

Liquibase provides the conditional preconditions and/or/not, which can be used with all other preconditions. In your case, wrap the <sqlCheck> with a <not>.

<preConditions onFail="MARK_RAN">
    <not>
        <sqlCheck expectedResult="0">SELECT COUNT(1) FROM tableB WHERE column2 IS NOT NULL;</sqlCheck>
    </not>
</preConditions>

See also the Preconditions documentation.

Roland Weisleder
  • 9,668
  • 7
  • 37
  • 59