mongodb初始化注销

This commit is contained in:
lvleigang 2024-08-23 15:06:36 +08:00
parent 43f01064ee
commit 2eaafe65d5
3 changed files with 26 additions and 22 deletions

View File

@ -18,7 +18,7 @@ spring:
# username: hzya # username: hzya
flyway: flyway:
# 启动flyway migration, 默认为true # 启动flyway migration, 默认为true
enabled: false enabled: true
datasource: datasource:
dynamic: dynamic:
druid: druid:

View File

@ -6,6 +6,8 @@ server:
tomcat: tomcat:
uri-encoding: utf-8 uri-encoding: utf-8
spring: spring:
autoconfigure:
exclude: org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration
flyway: flyway:
# 启动flyway migration, 默认为true # 启动flyway migration, 默认为true
enabled: true enabled: true

View File

@ -48,29 +48,31 @@ public class FlywayConfig {
@PostConstruct @PostConstruct
public void migrateOrder() { public void migrateOrder() {
String pwd = AESUtil.decrypt(password); if("false".equals(enabled)){
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource; String pwd = AESUtil.decrypt(password);
DataSource dsDatasource = null; DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
DataSource dsDatasource = null;
dsDatasource = ds.getDataSource("master"); dsDatasource = ds.getDataSource("master");
// 将路径转换 // 将路径转换
Flyway flyway = Flyway.configure() Flyway flyway = Flyway.configure()
//.dataSource(url,username,pwd) //.dataSource(url,username,pwd)
.dataSource(dsDatasource) .dataSource(dsDatasource)
.cleanDisabled(cleanDisabled) .cleanDisabled(cleanDisabled)
.locations(locations) .locations(locations)
.table(table) .table(table)
.encoding("utf-8") .encoding("utf-8")
.outOfOrder(true) .outOfOrder(true)
.baselineOnMigrate(true) .baselineOnMigrate(true)
.validateOnMigrate(baselineOnMigrate) .validateOnMigrate(baselineOnMigrate)
.validateOnMigrate(validateOnMigrat) .validateOnMigrate(validateOnMigrat)
.sqlMigrationPrefix(sqlMigrationPrefix) .sqlMigrationPrefix(sqlMigrationPrefix)
.sqlMigrationSeparator(sqlMigrationSeparator) .sqlMigrationSeparator(sqlMigrationSeparator)
.sqlMigrationSuffixes(sqlMigrationSuffixes) .sqlMigrationSuffixes(sqlMigrationSuffixes)
.placeholderReplacement(placeholderReplacement) .placeholderReplacement(placeholderReplacement)
.load(); .load();
flyway.migrate(); flyway.migrate();
}
} }
} }