flyway.setSchemas() 方法已被弃用,有什么替代方法?

4

我有一个多租户应用程序,需要对每个租户的模式进行数据迁移。但是当我在代码中使用flyway.setSchema()时,它会给出弃用警告。

有什么替代方案吗?

List<String> schemas = getExistingTenants();

for(int i=0;i < schemas.size(); i++)
{
Flyway flyway = Flyway.configure().dataSource(dataSource).load();
                    flyway.setSchemas(schemas.get(i));
            flyway.migrate();
}
2个回答

3

根据Flyway.setSchemas,直接配置Flyway对象已被弃用并将在Flyway 6.0中删除。请改用Flyway.configure()代替。

在您的情况下,应该像这样:

List<String> schemas = getExistingTenants();

for(int i = 0; i < schemas.size(); i++) {
    Flyway flyway = Flyway.configure().dataSource(dataSource)
                          .schemas(schemas.get(i)) // <-- configure schemas here using the
                          .load();                 // FluentConfiguration object's method
    flyway.migrate();                              // `schemas(String... schemas)`
}

另请参见:FluentConfiguration.schemas(String... schemas)

看起来 OP 想单独迁移模式(每个模式可能具有相同的结构),因此将 schemas 设置为列表(而不是单独设置)可能不是正确的方法。 - Mark Rotteveel
@MarkRotteveel 谢谢您指出这一点。我会澄清的。再次感谢 :) - lealceldeiro

3
正确的方法是在FluentConfiguration对象上执行此操作,就像您已经为dataSource配置所做的那样。请参考FluentConfiguration
Flyway flyway = Flyway.configure()
        .dataSource(dataSource)
        .schemas(schemas.get(i))
        .load();
flyway.migrate();

这也在Flyway.setSchemas文档中有说明:

已过时: 直接配置Flyway对象已被弃用,并将在Flyway 6.0中删除。请使用Flyway.configure()。

另请参阅问题1928


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接