M_F*_*M_F 6 xml migration variables properties liquibase
如果我要使用相同的变量但具有不同的值,如何替换下一个更改集的标记值。例子
<!-- 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_ = '${localization.key}' AND LOCALE = '${localization.locale}'</where>
</delete>
</rollback>
</changeSet>
Run Code Online (Sandbox Code Playgroud)
这个例子只适用于第一次第二次我有
设置或运行 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]
那么这个替换该如何进行呢?
默认情况下,Liquibase 属性全局应用,即使重新定义也将保持相同的值。
global从 Liquibase 3.4.0 开始,属性标签上有一个新属性。设置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>
Run Code Online (Sandbox Code Playgroud)