java - 按上下文名称运行 Liquibase 变更集

标签 java liquibase

有什么方法可以使用 Liquibase API 仅运行一组变更集吗?

以下代码在启动集成测试类之前初始化整个架构:

liquibase = new Liquibase(
    LIQUIBASE_CHANGELOG_PATH,
    new FileSystemResourceAccessor(),
    new JdbcConnection(embeddedTestDatabase.getConnection())
);
liquibase.dropAll();
liquibase.update(""); // PROBLEM: for some reason this launch all changesets including changesets with name `test`

现在我想在特定的测试方法之前执行类似 DBUnit 的 @DatabaseSetup 的操作 - 意味着仅使用 test 上下文执行变更集:

liquibase.update("test"); // PROBLEM : this also run all changesets

<changeSet author="me" id="some_id" logicalFilePath="some_path" context="test">
    <sql>
        INSERT INTO COMPANY (ID, CREATED_AT, CREATED_BY, NAME) VALUES (1, '2017-09-15 16:55:57.558', 'My company');
    </sql>
    <rollback>
        DELETE FROM COMPANY;
    </rollback>
</changeSet>

最佳答案

是的,the "contexts" feature in Liquibase在这里做你需要的事情。

文档中给出的示例符合您的要求。

文档解释:

When you run the migrator though any of the available methods, you can pass in a set of contexts to run. Only changeSets marked with the passed contexts will be run.

If you don’t assign a context to a changeSet, it will run all the time, regardless of what contexts you pass in to the migrator.

因此,如果您不希望它们在此处运行,我认为您需要向其余迁移添加除“测试”之外的上下文。也许是“main”?

关于java - 按上下文名称运行 Liquibase 变更集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46301364/

相关文章:

java - 打印 Collection 类元素的最佳方法是什么?

java - 点击 Android 屏幕解决媒体跳过问题,如何解决?

database - 未知参数 "includeObjects"在命令行 liquiBase 中引发异常

java - 使用 Liquibase 从远程数据库插入数据

java - 为什么 JMS MessageProducer 方法 setTimeToLive 或 send() 不起作用?

java - 我无法登录 Tomcat Manager 应用程序

java - 使用套接字发送帧

java - 在 spring boot 应用程序中使用默认和自定义 liquibase 配置

grails - dropPrimaryKey顺序错误

java - Liquibase 配置文件内容?