Skip to content

Commit

Permalink
Merge pull request #37 from besscroft/dev
Browse files Browse the repository at this point in the history
🐛flyway 初始化流程优化
  • Loading branch information
besscroft authored Aug 9, 2023
2 parents 6ae54e1 + fbdb826 commit 5f039b7
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,24 @@ public void flywayMigrate() {
}
String databaseProductVersion = databaseMetaData.getDatabaseProductVersion();
log.info("当前数据库版本为:{}", databaseProductVersion);
// 设置数据库是否初始化标志
boolean isInit = false;
if ("5".equals(StrUtil.sub(databaseProductVersion, 0, 1))) {
log.info("数据库版本不支持自动初始化,跳过初始化...");
log.warn("数据库版本不支持自动初始化,跳过初始化...");
return;
}
for (DatabaseType type : SORTED_DATABASE_TYPES) {
if (type.handlesDatabaseProductNameAndVersion(databaseProductName, databaseProductVersion, dataSource.getConnection())) {
log.info("数据库版本支持自动初始化,即将开始初始化...");
Flyway flyway = Flyway.configure().dataSource(dataSource).outOfOrder(true).locations("db/" + dbType + "/migration").load();
flyway.migrate();
isInit = true;
}
}
if (!isInit) {
log.warn("Unable to find a Flyway plugin for database: {}, with version: {}, and type: {}.", databaseProductName, databaseProductVersion, dbType);
return;
}
log.info("数据库初始化完毕!");
} catch (SQLException e) {
throw new DiyFileException(e.getMessage());
Expand Down

0 comments on commit 5f039b7

Please sign in to comment.