A few prerequisites

I am implementing a change set in Liquibase that requires several different prerequisites to be valid before it tries to execute.

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

Scenario # 2: If table X, Y, Z does not exist, terminate the change set

In other words, I need two <preConditions> with different onFail . Is this possible in liquibase? I can't seem to get it to work. docs are not very informative.

+4
source share
3 answers

This is currently prohibited. There can only be one block.

Will it work to split it into two separate sets of changeSets?

+3
source

The workaround that I just 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> 
+2
source

Combine them with <or> or <and> as follows:

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

There is preConditions documentation here.

+1
source

Source: https://habr.com/ru/post/1502745/


All Articles