0
votes

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?

1
What version of liquibase are you using? - Jens
What if you just change the expectedResult from 1 to 0? - Jens
When your precondition fails you should see some log output that this happened. And it should stop to execute since you configured it to halt in this case. I wonder if this works at all. - Jens
same result - it acts like there is no precondition in all cases (as sql comment, SQL-condition in changelog-xml & property-condition in changelog-xml) - Stefan Fuchs
Strange. I have no idea what could be wrong. It looks good to me... - Jens

1 Answers

0
votes

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