【问题标题】:liquibase roll back with spring bootliquibase 用弹簧靴回滚
【发布时间】:2021-01-18 01:49:35
【问题描述】:

我有一个 spring boot 应用程序(v2.3.3),其中包含 Liquidbase 工具来创建我的表并对其进行初始化。 当我启动 spring boos 时,它工作正常,使用 sql 脚本创建表并插入数据,Liquidbase 配置如下所示:

application.yml:

spring:
  liquibase:
    change-log: classpath:db/db.master.xml

src/main/resources/db: db.master.xml

<?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-2.0.xsd">
    <includeAll path="scripts/" relativeToChangelogFile="true"/>`enter code here`

</databaseChangeLog>

src/main/resources/db/script/

  • 001.createTableAudit.sql
  • 002.insertDataTableAudit.sql

假设我要回滚 002.insertDataTableAudit.sql,是否可以回滚 insertDataTableAudit 何时启动我的 Spring Boot 应用程序?

我知道它可以由 maven 完成:mvn liquibase:rollback 但是否可以使用 Spring Boot 实现相同的目标?

提前致谢

【问题讨论】:

    标签: spring spring-boot spring-data-jpa liquibase


    【解决方案1】:

    我认为开箱即用的 spring boot 中没有这样的功能。 但是,您可以轻松地创建该功能:

    final Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
    final Liquibase liquibase = new Liquibase("changelogpath", new CompositeResourceAccessor(new ClassLoaderResourceAccessor(), new FileSystemResourceAccessor()), database);
    liquibase.rollback("TAG", (String) null);
    

    【讨论】:

      猜你喜欢
      • 2018-09-13
      • 2017-12-22
      • 2018-02-14
      • 2019-05-03
      • 2021-04-20
      • 1970-01-01
      • 2023-01-07
      • 2021-12-08
      • 1970-01-01
      相关资源
      最近更新 更多