如何仅执行 liquibase 中未读的特定变更集?

Deb*_*der 3 liquibase

我在现有变更日志文件中添加了一些新的变更集,并且只想执行新插入的变更集中的 2 个。当我在 liquibase 中发出更新命令时,它会更新所有未读的变更集并更新数据库。但我只想执行变更日志文件中这些新插入的变更集中的 2 个。在liquibase中有什么方法可以做到这一点吗?如果是的话怎么可能?

Ste*_*nie 5

执行此操作的一种方法是使用标签标记相关变更集,然后在liquibase update命令中使用该标签。

这篇关于标签的博客文章描述了它们的用途。

这是一个与您在下面的评论中描述的内容相匹配的示例。

变更日志

<?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>
Run Code Online (Sandbox Code Playgroud)

命令执行

如果您想更新并仅创建表一,您可以使用此命令(如果您使用命令行,并假设您有一个指定所有连接信息等的 liquibase.properties 文件)

liquibase --changeLogFile=changelog.xml --labels=labelOne update
Run Code Online (Sandbox Code Playgroud)

如果您想应用两个变更集,您可以使用如下命令:

liquibase --changeLogFile=changelog.xml --labels="labelOne and labelTwo" update
Run Code Online (Sandbox Code Playgroud)