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.
It is not allowed currently. There can be just one block.
Would it work to break it up into two separate changeSets?
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>
Combine them with <or>
or <and>
like this:
<preConditions>
<or>
<runningAs username="liquibase" />
<runningAs username="sa" />
</or>
</preConditions>
Here is some documentation on preConditions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With