Closed Li-Jin closed 4 years ago
你可以利用系统启动初始化来执行一次。
已处理好,整合flyway 在动态数据源里面拿出所有数据源 循坏遍历数据源,flyway执行升级脚本
public class FlywayConfiguration {
private final DynamicRoutingDataSource dataSourceProperties;
public FlywayConfiguration(DynamicRoutingDataSource dataSourceProperties) {
this.dataSourceProperties = dataSourceProperties;
}
@PostConstruct
public void migrate() {
Map<String, DataSource> dataSourceMap = dataSourceProperties.getCurrentDataSources();
dataSourceMap.forEach((k, v) -> {
Flyway flyway = Flyway.configure().dataSource(v).load();
flyway.setBaselineOnMigrate(true);
flyway.setCleanDisabled(true);
flyway.setBaselineVersion(MigrationVersion.fromVersion("0"));
flyway.migrate();
});
}
}
Enviroment
JDK Version(required): 1.8
SpringBoot Version(required): 2.2
dynamic-datasource-spring-boot-starter Version(required):3.2+
druid Version(optional):1.1.21
Describe
场景:多数据源,多租户,所有租户数据库完全相同,系统升级数据库升级脚本需要在系统中根据所有数据源进行升级