Liquibase回滚Spring引导 [英] Liquibase Rollback Spring boot

查看:319
本文介绍了Liquibase回滚Spring引导的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Spring Boot构建的微服务.我集成了Liquibase,它执行除回滚之外的所有 changeSet . 以下是样本liquibase xml文件.

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>

当我运行spring boot应用程序时,它不执行回滚.但是在数据库中,更改会随着执行而更新.

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

推荐答案

在您的示例中,changeSet id="7"没有实际变化.这只是一个回滚语句,在逻辑上是不正确的,因为没有任何表作为更改集的一部分被删除.您可以参考回滚ChangeSet文档有关如何编写回滚的信息.

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.

当您将架构迁移到较低版本时,应该执行回滚降级Spring Boot应用程序版本后.这不是Spring Boot的开箱即用的功能,Spring Boot仅通过常规的Liquibase更新操作应用缺少的变更集.

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.

Spring Boot中有一个liquibase.rollback-file属性,可用于编写回滚SQL脚本.回滚架构时,您必须手动运行此SQL.您可以尝试 Maven Liquibase插件将其自动化.

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.

这篇关于Liquibase回滚Spring引导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆