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:
@@ -130,10 +130,6 @@ spring:
|
||||
# 多久检查一次连接的活性
|
||||
keepaliveTime: 30000
|
||||
|
||||
flyway:
|
||||
baseline-on-migrate: true # 第一次运行时建立记录,不执行历史脚本
|
||||
clean-disabled: true # 禁止清空库
|
||||
|
||||
--- # redis 单机配置(单机与集群只能开启一个另一个需要注释掉)
|
||||
spring:
|
||||
redis:
|
||||
|
||||
@@ -124,10 +124,6 @@ spring:
|
||||
# 多久检查一次连接的活性
|
||||
keepaliveTime: 30000
|
||||
|
||||
flyway:
|
||||
baseline-on-migrate: true # 第一次运行时建立记录,不执行历史脚本
|
||||
clean-disabled: true # 禁止清空库
|
||||
|
||||
--- # redis 单机配置(单机与集群只能开启一个另一个需要注释掉)
|
||||
spring:
|
||||
redis:
|
||||
|
||||
@@ -101,11 +101,6 @@ spring:
|
||||
deserialization:
|
||||
# 允许对象忽略json中不存在的属性
|
||||
fail_on_unknown_properties: false
|
||||
# 实时更新数据库结构
|
||||
flyway:
|
||||
enabled: true
|
||||
locations: classpath:db/migration
|
||||
table: flyway_schema_history
|
||||
|
||||
# Sa-Token配置
|
||||
sa-token:
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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 数据库迁移完成 ==========");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
import org.flywaydb.core.internal.util.StringUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import com.klp.common.annotation.RepeatSubmit;
|
||||
|
||||
6
pom.xml
6
pom.xml
@@ -363,12 +363,6 @@
|
||||
<version>${klp-flowable-plus.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 引入flyway -->
|
||||
<dependency>
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-core</artifactId>
|
||||
<version>8.5.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.klp</groupId>
|
||||
<artifactId>klp-ems</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user