refactor(database): 移除Flyway数据库迁移配置

- 从application.yml中移除flyway相关配置项
- 从application-dev.yml中移除flyway相关配置项
- 从application-prod.yml中移除flyway相关配置项
- 将EmsEnergyConsumptionController中的StringUtils替换为Spring工具类
- 删除FlywayConfig配置类及其命令行启动器实现
- 从klp-common模块的pom.xml中移除flyway依赖
- 从根pom.xml中移除flyway核心依赖
This commit is contained in:
2026-03-16 09:29:53 +08:00
parent 319553702e
commit 8972a45fcc
7 changed files with 1 additions and 98 deletions

View File

@@ -170,16 +170,6 @@
<artifactId>ip2region</artifactId>
</dependency>
<!-- 引入flyway -->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-mysql</artifactId>
</dependency>
<!-- 动态数据源依赖 -->
<dependency>
<groupId>com.baomidou</groupId>

View File

@@ -1,68 +0,0 @@
package com.klp.common.config;
import javax.annotation.Resource;
import javax.sql.DataSource;
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.output.MigrateResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FlywayConfig {
@Value("${spring.profiles.active}")
private String activeProfile;
@Value("${spring.flyway.baseline-on-migrate}")
private boolean baselineOnMigrate;
@Value("${spring.flyway.locations}")
private String locations;
@Value("${spring.flyway.table}")
private String table;
@Resource
private DataSource dataSource;
@Bean
public Flyway flyway() {
DataSource masterDataSource = ((DynamicRoutingDataSource) dataSource).getDataSource("master");
System.out.println("masterDataSource class: " + masterDataSource.getClass().getName());
// // 如果想显式拿底层 HikariDataSource
// if (masterDataSource instanceof ItemDataSource) {
// masterDataSource = ((ItemDataSource) masterDataSource).getRealDataSource();
// }
System.out.println("masterDataSource class: " + masterDataSource.getClass().getName());
return Flyway.configure()
.dataSource(masterDataSource) // 注意这里是真实主库 DataSource
.baselineOnMigrate(baselineOnMigrate)
.locations(locations)
.table(table)
.load();
}
@Bean
public CommandLineRunner flywayRunner(Flyway flyway) {
return args -> {
System.out.println("========== 当前环境: " + activeProfile + " ==========");
System.out.println("========== 开始执行 Flyway 数据库迁移 ==========");
MigrateResult result = flyway.migrate();
System.out.println("迁移成功版本数: " + result.migrationsExecuted);
result.migrations.forEach(m -> {
System.out.println("执行版本: " + m.version + ",描述: " + m.description);
});
System.out.println("========== Flyway 数据库迁移完成 ==========");
};
}
}