Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple PreConditions

Tags:

liquibase

I am implementing a changeset in Liquibase that needs a few different preconditions to be valid before it attempts to run.

Scenario #1: If table A,B,C exists, mark as ran

Scenario #2: If table X,Y,Z doesn't exist, halt execution of changeset

In other words, I need two <preConditions> tags with different onFail clauses. Is this at all allowed in Liquibase? I can't seem to make it work. The docs aren't very informative.

like image 655
Kris Selbekk Avatar asked Sep 18 '13 07:09

Kris Selbekk


3 Answers

It is not allowed currently. There can be just one block.

Would it work to break it up into two separate changeSets?

like image 76
Nathan Voxland Avatar answered Nov 05 '22 01:11

Nathan Voxland


A workaround that I've simply used:

  • create a normal precondition

    <!-- pre-condition tests -->
    <preConditions onFail="WARN">
            <runningAs username="${db.maintenance.user}" />
    </preConditions>
    
  • create an empty changeSet for another onFail level

    <changeSet id="liquibase-pre-1" author="liquibase" runAlways="true" runOnChange="true" runInTransaction="false">
        <preConditions onFail="HALT" onFailMessage="...">
            <!-- ... -->
        </preConditions>
        <sql>
            select 1 <!-- (Postgresql) or "select 1 from dual" (Oracle) -->
        </sql>
    </changeSet>
    
like image 35
gudepier Avatar answered Nov 05 '22 03:11

gudepier


Combine them with <or> or <and> like this:

<preConditions>
    <or>
        <runningAs username="liquibase" />
        <runningAs username="sa" />
    </or>
</preConditions>

Here is some documentation on preConditions.

like image 32
Jens Avatar answered Nov 05 '22 03:11

Jens