package com.lesingle.common.config;

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 修复配置
 * 启动时自动修复失败的迁移记录，然后执行迁移
 */
@Configuration
public class FlywayRepairConfig {

    @Bean
    public FlywayMigrationStrategy flywayMigrationStrategy() {
        return flyway -> {
            // 先修复失败的迁移记录
            flyway.repair();
            // 然后执行迁移
            flyway.migrate();
        };
    }
}
