代码之家  ›  专栏  ›  技术社区  ›  aurelius

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

  •  3
  • aurelius  · 技术社区  · 8 年前

    我有两个changeLog文件(changeLog-1.0.1.xml,changeLog-2.0.1.xml)。 每个变更日志文件包含两个变更集(变更集-1、变更集-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\3.5.3\liquibase-core-3.5.3.jar update rollback changeSet-1 --changeLogFile="changeLog-1.0.1.xml"
    

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

    update:我成功地从命令行调用update

        java -jar C:\Users\someUser\.m2\repository\org\liquibase\liquibase-core\3.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\3.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
    
    1 回复  |  直到 8 年前
        1
  •  2
  •   aurelius    8 年前

    我必须先创建一个标记

    java -jar C:\path\.m2\repository\org\liquibase\liquibase-core\3.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\3.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