Search code examples
liquibasesap-ase

Liquibase precondition is ignored


I want to add some data only on development database for test purposes. To do so, I created a test_data.sql that is included using

<include file="./test_data.sql" relativeToChangelogFile="true"/>

The test_data.sql is formatted as follows:

--liquibase formatted sql

--changeset whiad-16453:testdata runOnChange:true failOnError:true endDelimiter:go stripComments:false
--preconditions onFail:HALT onError:HALT
--precondition-sql-check expectedResult:1 select case when db_name()='devdb' then 1 else 0 end
insert into...

I expected that the insert is only performed, when the select returns 1 (it is a Sybase SQL dialect and I executed the query both on Dev and Prod environment using Sybase Central and it return 0 or 1 as expected). Nevertheless, Liquibase created a script including the inserts (using updateSQL commandline argument).

I alternatively tried to use the precondition right before the include file in the changelog:

<preConditions>
    <sqlCheck expectedResult="1">select case when db_name()='devdb' then 1 else 0 end</sqlCheck>
</preConditions>
<include file="./test_data.sql" relativeToChangelogFile="true"/>

But also in this case the insert where perfomed. I also tried to used a property that i use in the condition:

<changeLogPropertyDefined property="deploy_test_data" value="true"/>

But this also didn't had any effect.

What do I do wrong?


Solution

  • I used now the context for my purpose passing "contexts==!testdata" as parameter on prod.