在同一台服务器上基于两个数据库,每个数据库都有自己的起始迁移脚本编号为V2__
,我收到以下错误:
flyway:baseline
产生错误
Found more than one migration with version 2
每个迁移脚本都位于自己的迁移目录中:db/migration/db1, db/migration/db2
我是否错过了配置,或者这是预期的?
答案 0 :(得分:0)
我了解到只使用属性文件迁移多个数据库是不可能的。它只能通过使用Java代码触发迁移来实现,所以我连接了一个bean来处理这个问题:
@Configuration
public class FlywaySlaveInitializer {
@Autowired
Environment env;
@Bean(initMethod = "migrate")
@PostConstruct
Flyway flyway() {
String datasource = env.getProperty("flyway.url");
String[] schemas = env.getProperty("flyway.schemas").split(",");
String[] schemaLocations = env.getProperty("flyway.locations").split(",");
Flyway flyway = new Flyway();
for (int schema = 0; schema < schemas.length; schema++) {
flyway.setDataSource(datasource + "/" + schemas[schema], "root", "root");
flyway.setSchemas(schemas[schema]);
flyway.setLocations("db/migration/" + schemaLocations[schema]);
flyway.migrate();
}
return flyway;
}
}