Liquibase Rollback Spring boot

淺唱寂寞╮ 提交于 2020-01-04 05:50:34

问题


I have a microservice built using spring boot. I integrated the Liquibase and it execute all changeSets except rollbacks. Below is the sample liquibase xml file.

<changeSet id="6" author="Kasun">
        <insert tableName="user">
            <column name="firstNale" value="Kasun" ></column>
            <column name="lastName" value="Ranasinghe" ></column>
        </insert>
    </changeSet>
    <changeSet id="7" author="Kasun">
        <rollback changeSetAuthor="Kasun"  >
            <createTable tableName="user" />
        </rollback>
    </changeSet>

When I run the spring boot app it doesn’t execute the rollback. But in the database changes is updated as executed.


回答1:


In your example changeSet id="7" has no actual change. it's just a rollback statement which is logically incorrect as no table is being dropped as part of the changeset. You can refer to Rolling Back ChangeSets docs on how to write rollbacks.

Rollbacks are supposed to be executed when you migrate the schema to lower version e.g. after downgrading the Spring Boot application version. This is not something which is done out of the box by Spring Boot which only applies the missing changesets using the regular Liquibase update operation.

There is a liquibase.rollback-file property in Spring Boot which can be used to write a rollback SQL script. You'd have to run this SQL by hand when you are rolling back the schema. You can try Maven Liquibase Plugin to automate it.



来源:https://stackoverflow.com/questions/49634064/liquibase-rollback-spring-boot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!