Check if not null or not 0 in Liquibase Precondition
Asked Answered
E

1

5

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

Educatory answered 10/1, 2019 at 16:35 Comment(0)
D
14

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.

Demodena answered 10/1, 2019 at 17:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.