0

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?

6
  • What version of liquibase are you using?
    – Jens
    Commented Jun 1, 2016 at 12:17
  • What if you just change the expectedResult from 1 to 0?
    – Jens
    Commented Jun 1, 2016 at 12:55
  • 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
    Commented Jun 1, 2016 at 13:00
  • 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) Commented Jun 1, 2016 at 13:39
  • Strange. I have no idea what could be wrong. It looks good to me...
    – Jens
    Commented Jun 1, 2016 at 14:37

1 Answer 1

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.