【问题标题】:liquibase configuration with 2 master files - is it possible?带有 2 个主文件的 liquibase 配置 - 可以吗?
【发布时间】:2020-05-12 19:21:09
【问题描述】:

我需要为某些测试运行特定的迁移。所以我想将此测试迁移与其他迁移分开。我正在考虑制作第二个 liquibase 主文件(test/resources/db/liquibase-master.xml),其中包括我只需要用于测试的第一个 + 迁移。我不确定这是否可能。这是正确的方法,还是有其他更好的方法?

【问题讨论】:

  • 我从未尝试过,但 LiquibaseProperties bean 有一个 changeLog 属性。所以你应该能够在你的默认 application.properties 文件中设置一个主文件,并在你的 application-test.properties 文件中为测试配置文件设置另一个主文件
  • 另一种选择是拥有 1 个适用于所有配置文件的唯一主文件,并使用 ChangeSetcontext 属性进行设置,在这种情况下将应用 ChangeSet

标签: java spring-boot liquibase


【解决方案1】:

以下是使用 1 个主文件和使用上下文来实现您所需的方法。还有关于它的文档:https://www.liquibase.org/documentation/contexts.html

开发配置:src/main/config/application-dev.yml

  liquibase:
    contexts: dev

测试配置:src/test/config/application.yml

  liquibase:
    contexts: test

变更集示例:ChangeSet_xxx_.xml

<changeSet id="x1" context="dev">
 <!-- Executed in dev context only -->
</changeSet>

<changeSet id="x2" context="test">
 <!-- Executed in test context only -->
</changeSet>

<changeSet id="x3" context="test,dev">
 <!-- Executed in both contexts -->
</changeSet>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-16
    • 2015-05-29
    • 1970-01-01
    • 1970-01-01
    • 2012-05-09
    • 2011-12-26
    • 2015-06-29
    相关资源
    最近更新 更多