nansen
nansen

Reputation: 2962

Liquibase: check if a property was set

I could not find a way to check in a precondition element if a custom property is set.

What I found out about this issue so far is here. As the ticket comment indicates, extending CustomPrecondition will not help without modifying the API. Is there another way?

Upvotes: 3

Views: 3499

Answers (1)

Mark O'Connor
Mark O'Connor

Reputation: 77971

The documentation describes a changeLogPropertyDefined precondition.

The following example worked fine for me:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">

    <changeSet author="mark (generated)" id="mark-1">
        <preConditions onFail="HALT">
            <changeLogPropertyDefined property="testing" value="1"/>
        </preConditions>

        <createTable tableName="TEST001">
            <column name="ID" type="VARCHAR(10)">
                <constraints nullable="false"/>
            </column>
            <column name="X" type="VARCHAR(9)">
                <constraints nullable="false"/>
            </column>
            <column name="Y" type="DECIMAL(7,2)"/>
            <column name="Z" type="DECIMAL(7,2)"/>
        </createTable>
    </changeSet>

</databaseChangeLog>

I run liquibase from Maven. The testing property can be set from the command line as follows:

mvn -Dtesting=1 compile

Upvotes: 8

Related Questions