如何使用 Liquibase 命令行回滚到特定的更改集

How to rollback to a specific change set with Liquibase Command Line

我有两个 changeLog 文件(changeLog-1.0.1.xml、changeLog-2.0.1.xml)。 每个 changeLog 文件包含两个 changeSets (changeSet-1, changeSet-1) 两者都在应用程序部署时执行。

这是我指定变更集的方式:

<changeSet id="changeSet-1" author="someUser" labels="labelOne">
    <createTable tableName="testTable" schemaName="public">
        <column autoIncrement="true" name="id" type="BIGINT">
            <constraints primaryKey="true"/>
        </column>
    </createTable>
    <rollback>
        <dropTable tableName="testTable"/>
    </rollback>
</changeSet>

我想从命令行回滚第二个 changeLog 文件 (changeLog2.xml)。

我试了很多方法都没有成功

java -jar C:\..\.m2\repository\org\liquibase\liquibase-core.5.3\liquibase-core-3.5.3.jar update rollback changeSet-1 --changeLogFile="changeLog-1.0.1.xml"

当与 changeLog 文件位于同一目录时

更新:我成功地从命令行调用了更新

    java -jar C:\Users\someUser\.m2\repository\org\liquibase\liquibase-core.5.3\liquibase-core-3.5.3.jar 
--changeLogFile=changeLog.xml 
--labels=labelOne 
--url=jdbc:postgresql://localhost:5432/app2db 
--classpath=C:/postgresql-42.1.4.jar 
--username=app2user 
--password=password 
update

和回滚

    java -jar C:\Users\someUser\.m2\repository\org\liquibase\liquibase-core.5.3\liquibase-core-3.5.3.jar 
--changeLogFile=changeLog.xml 
--labels=labelOne 
--url=jdbc:postgresql://localhost:5432/app2db 
--classpath=C:/postgresql-42.1.4.jar 
--username=app2user 
--password=password 
rollback

调用崩溃

Unexpected error running Liquibase: rollback requires a rollback tag

我必须先创建一个标签

java -jar C:\path\.m2\repository\org\liquibase\liquibase-core.5.3\liquibase-core-3.5.3.jar  
--changeLogFile=changeLog.xml
--url=jdbc:postgresql://localhost:5432/app2db
--classpath=C:/postgresql-42.1.4.jar
--username=app2user
--password=password
tag exampletag

然后回滚到该特定标签

java -jar C:\path\.m2\repository\org\liquibase\liquibase-core.5.3\liquibase-core-3.5.3.jar
--changeLogFile=changeLog.xml
--labels=labelOne
--url=jdbc:postgresql://localhost:5432/app2db
--classpath=C:/postgresql-42.1.4.jar
--username=app2user
--password=password
rollback exampletag