【发布时间】:2018-04-27 11:20:21
【问题描述】:
我正在尝试在我的 Web 应用程序中使用 Flyway。我已阅读文档,但找不到以下问题的答案:
是否可以在运行migrate 之前检查数据库是否为baselined?
Web 应用程序已经使用了一个大型数据库。所以我需要为此运行baseline。我希望应用程序在启动时运行 baseline 和/或 migrate。如果数据库不存在则应创建该数据库,如果存在则应为baselined,但之前不是baselined。
我已经在迁移包中添加了 3 个 SQL 文件:
V4_0_0__schema.sql
V4_0_1__index.sql
V4_0_2__initial_inserts.sql
我想这样做:
DataSource dataSource = new MysqlDataSource();
String[] locations = {"path/to/location"};
Flyway flyway = new Flyway();
flyway.setCleanDisabled(true);
flyway.setLocations(locations);
flyway.setDataSource(dataSource);
if (databaseExists()) { // how to determine that the db already exists?
if (databaseWasBaselined() == false) { // How to check this?
flyway.setBaselineVersion(MigrationVersion.LATEST); // will this set the version to 4_0_2?
flyway.baseline();
}
}
flyway.migrate();
我需要一点帮助才能以正确的方式进行操作。我希望有人能指出我正确的方向。
【问题讨论】: