Liquibase:检查是否设置了属性

时间:2012-04-24 12:12:55

标签: liquibase

如果设置了自定义属性,我找不到检查前提条件元素的方法。

到目前为止,我发现的这个问题是here。 如故障单注释所示,如果不修改API,扩展CustomPrecondition将无济于事。还有另一种方式吗?

1 个答案:

答案 0 :(得分:5)

documentation描述了 changeLogPropertyDefined 前置条件。

以下示例对我来说很好:

<?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>

我从Maven运行liquibase。可以从命令行设置testing属性,如下所示:

mvn -Dtesting=1 compile