在admin模块的pom.xml增加依赖
< ! -- 数据库版本控制 -->
< dependency>
< groupId> org.flywaydb< /groupId>
< artifactId> flyway-core< /artifactId>
< version> 7.15 .0 < /version>
< /dependency>
在admin模块下的resources 的配置文件spring下增加
flyway:
enabled: true
encoding: utf-8
baseline-description: BaseLineInitialize
baseline-version: 1.0 .0
out-of-order: false
ignore-future-migrations: false
locations: classpath:db/migration
validate-on-migrate: true
clean-disabled: false
baseline-on-migrate: true
table: flyway_schema_history
在framework 下面定义flyway配置bean
package com.qilaike.framework.config;
import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import org.flywaydb.core.Flyway;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FlywayConfig {
@Autowired
private DataSource dataSource;
// 字符编码
@Value( "${spring.flyway.encoding} " )
private String encoding;
// 对执行迁移时基准版本的描述
@Value( "${spring.flyway.baseline-description} " )
private String baselineDescription;
// 是否自动执行基准迁移
@Value( "${spring.flyway.baseline-on-migrate} " )
private boolean baselineOnMigrate;
// 指定 baseline 的版本号
@Value( "${spring.flyway.baseline-version} " )
private String baselineVersion;
// 迁移时是否校验
@Value( "${spring.flyway.validate-on-migrate} " )
private boolean validateOnMigrate;
// 是否允许无序的迁移
@Value( "${spring.flyway.out-of-order} " )
private boolean outOfOrder;
// 当读取元数据表时是否忽略错误的迁移
@Value( "${spring.flyway.ignore-future-migrations} " )
private boolean ignoreFutureMigrations;
// 当初始化好连接时要执行的SQL
//@Value( "${flyway.init-sql} " )
//private String initSql;
@PostConstruct
public void migrate ( ) {
Flyway flyway = Flyway.configure( )
.dataSource( dataSource)
.encoding( encoding)
.baselineDescription( baselineDescription)
.baselineOnMigrate( baselineOnMigrate)
.baselineVersion( baselineVersion)
.validateOnMigrate( validateOnMigrate)
.outOfOrder( outOfOrder)
.ignoreFutureMigrations( ignoreFutureMigrations)
//.initSql( initSql)
.load( ) ;
flyway.migrate( ) ;
}
}
在admin模块下的resources下面增加目录db/migration 开始在db/migration下面增加sql文件,文件命名有要求 启动项目,看看自己的sql是否生效,生效则成功,其他情况自己解决去吧!