【问题标题】:Liquibase replace <property> tag value?Liquibase 替换 <property> 标签值?
【发布时间】:2018-01-29 09:25:18
【问题描述】:

如果我要使用相同的变量但具有不同的值,如何替换下一个更改集的标记值。示例

<!-- TRANSLATION -->
<property name="localization.table"     value="LOCALIZATION"/>
<property name="localization.locale"    value="en_US"/>
<!-- -->
<property name="localization.key"       value="translation.key"/>
<!-- Translation -->
<property name="localization.value"     value="translation"/>
<!-- -->

<changeSet author="me" id="translate">

    <insert tableName="${localization.table}">
        <column name="KEY_">${localization.key}</column>
        <column name="VALUE">${localization.value}</column>
        <column name="LOCALE">${localization.locale}</column>
    </insert>

    <rollback>
        <delete tableName="${localization.table}">
            <!-- Doesnt work with regular '' symbols -->
            <where>KEY_ = &apos;${localization.key}&apos; AND LOCALE = &apos;${localization.locale}&apos;</where>
        </delete>
    </rollback>

</changeSet>

这个例子只有第一次第二次才有效

设置或运行 Liquibase 时出错:liquibase.exception.SetupException:liquibase.exception.SetupException:解析 /patches/translate_me.xml 的第 150 行第 67 列时出错:cvc-complex-type.2.4.a:发现无效内容从元素“属性”开始。需要 '{"http://www.liquibase.org/xml/ns/dbchangelog":changeSet, "http://www.liquibase.org/xml/ns/dbchangelog":include, "http://www.liquibase.org/xml/ns/dbchangelog":includeAll}' 之一。 -> [帮助 1]

那么这个替换怎么做呢?

【问题讨论】:

    标签: xml variables properties migration liquibase


    【解决方案1】:

    默认情况下,Liquibase 属性是全局应用的,即使重新定义也会保持相同的值。

    从 Liquibase 3.4.0 开始,属性标签上有一个新的 global 属性。设置global="false" 会将属性限制为定义在其中的databaseChangeLog,从而允许您在不同的databaseChangeLog 中使用具有新值的该属性。

    如果您需要重新定义属性,则需要在新的databaseChangeLog 中完成。在你的具体情况下,我相信你有一个语法错误,因为你试图在同一个 databaseChangeLog 中的 changeSet 之后定义一个属性。

    例子:

    <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-3.5.xsd">
        <property name="myProperty" value="foo" global="false"/>
    
        <changeSet author="me" id="changeSet-1">
            <!-- will insert `foo` -->
            <insert tableName="my_table">
                <column name="my_column">${myProperty}</column>
            </insert>
        </changeSet>
    </databaseChangeLog>
    
    
    <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-3.5.xsd">
        <property name="myProperty" value="bar" global="false"/>
    
        <changeSet author="me" id="changeSet-2">
            <!-- will insert `bar` -->
            <insert tableName="my_table">
                <column name="my_column">${myProperty}</column>
            </insert>
        </changeSet>
    </databaseChangeLog>
    

    【讨论】:

      猜你喜欢
      • 2021-12-27
      • 1970-01-01
      • 2010-12-12
      • 2022-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-11
      相关资源
      最近更新 更多