我正在使用Liquibase 3.4.2(通过Maven插件) . 我有一个 db.changelog-master.xml 文件,其中包含另外两个文件: db.changelog-2.6.xml 和 db.changelog-2.10 .
db.changelog-master.xml 看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog logicalFilePath="/database-migration/db.changelog-master.xml"
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.4.xsd">
<include file="versions/db.changelog-2.6.xml" relativeToChangelogFile="true"/>
<include file="versions/db.changelog-2.10.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>
在 db.changelog-2.10 我正在创建 <changeSet>
以删除一些数据,并且在 <rollback>
标签中我引用了创建相同数据的 <changeSet>
. 这两个 <changeSet>
看起来像这样:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog logicalFilePath="/database-migration/versions/db.changelog-2.10.xml"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
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.4.xsd">
<changeSet id="1" author="my-user">
<insert tableName="TABLE">
<!-- SOME DATA -->
</insert>
</changeSet>
<changeSet id="2" author="my-user">
<delete tableName="TABLE" />
<rollback changeSetId="1" changeSetAuthor="my-user" />
</changeSet>
</databaseChangeLog>
问题是,当我尝试运行 update
命令时,我最终得到以下错误消息:
更改集/database-migration/versions/db.changelog-2.10.xml::1::my-user不存在
我做错了什么或者这是一个Liquibase错误?
2 回答
请检查
<changeSet id="1">
中打开和关闭XML标签的匹配情况 . 在您的示例中,我看到打开标记<insert>
并关闭标记</update>
. 也许您的问题导致输入数据不正确 . liquibase中的XML解析器没有检测到这一点,这很奇怪 .尝试将结束标记
</update>
替换为更合适的</insert>
.添加changeSetPath属性
change_log_master:
... <include file="scripts/my_rollback_script.xml"/> <include file="scripts/the_script_change_log.xml"/> ...
the_script_change_log.xml:
... <rollback changeSetId="my_rollback_script_id" changeSetAuthor="me" changeSetPath="scripts/my_rollback_script.xml" /> ...