feat: Flyway 启动自动 repair → migrate,应用自愈失败迁移记录

- FlywayConfig: 自定义 FlywayMigrationStrategy
- 启动时先 flyway.repair() 清理残留失败记录
- 再 flyway.migrate() 执行待迁移
- 全程应用内完成,无需外部操作
This commit is contained in:
mediabot-pt
2026-06-30 10:44:41 +08:00
parent da79a2dd70
commit 8d8e066e6d
2 changed files with 26 additions and 1 deletions

View File

@@ -0,0 +1,26 @@
package com.par.api.config;
import lombok.extern.slf4j.Slf4j;
import org.flywaydb.core.Flyway;
import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Flyway 自动修复配置
* 启动时自动清理残留的失败迁移记录,再执行待迁移
*/
@Slf4j
@Configuration
public class FlywayConfig {
@Bean
public FlywayMigrationStrategy flywayMigrationStrategy() {
return (Flyway flyway) -> {
log.info("Flyway repair: cleaning failed migration records...");
flyway.repair();
log.info("Flyway migrate: applying pending migrations...");
flyway.migrate();
};
}
}

View File

@@ -31,7 +31,6 @@ spring:
locations: classpath:db/migration
baseline-on-migrate: true
baseline-version: 0
repair-on-migrate: true
mybatis-plus:
configuration: