有什么方法可以使用 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/