我在现有的changelog文件中添加了一些新的更改集,并且只想在新插入的文件中执行2个。当我在liquibase中提供update命令时,它会更新所有未读的更改集并更新数据库。但我想在changelog文件中只在这些新插入的变更集中执行2。有没有办法在liquibase中这样做?如果是的话怎么可能?
答案 0 :(得分:4)
您可以这样做的一种方法是使用标签标记相关的变更集,然后在liquibase update
命令中使用该标签。
此blog post on labels描述了它们的用途。
以下示例与您在下面的评论中描述的内容相符。
<强>更改日志强>
<?xml version="1.0" encoding="UTF-8"?>
<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">
<changeSet id="1" author="steve" labels="labelOne">
<createTable tableName="tableOne">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false" />
</column>
</createTable>
</changeSet>
<changeSet id="2" author="steve" labels="labelTwo">
<comment>Creating table "tableTwo"</comment>
<createTable tableName="tableTwo">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false" />
</column>
</createTable>
</changeSet>
<changeSet id="3" author="steve" labels="labelThree">
<comment>Creating table "tableThree"</comment>
<createTable tableName="tableThree">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false" />
</column>
</createTable>
</changeSet>
</databaseChangeLog>
执行命令
如果你想更新并只创建第一个表,你可以使用这个命令(如果你使用命令行,并假设你有一个指定所有连接信息的liquibase.properties文件等)。 p>
liquibase --changeLogFile=changelog.xml --labels=labelOne update
如果要应用两个更改集,可以使用如下命令:
liquibase --changeLogFile=changelog.xml --labels="labelOne and labelTwo" update