springboot - 整合flyway

一、概念

官网:Homepage - Flyway

数据库版本控制管理工具,通过集成Flyway可以实现启动项目时自动执行项目迭代升级。

Flyway已经支持数据库包括:Oracle, SQL Server, SQL Azure, DB2, DB2 z/OS, MySQL (including Amazon RDS), MariaDB, Google Cloud SQL, PostgreSQL (including Amazon RDS and Heroku), Redshift, Vertica, H2, Hsql, Derby, SQLite, SAP HANA, solidDB, Sybase ASE and Phoeni

二、集成

1、依赖

<dependency>
      <groupId>org.flywaydb</groupId>
      <artifactId>flyway-core</artifactId>
      <version>8.2.0</version>
</dependency>

 2、配置

##是否启动,默认开启
spring.flyway.enabled = true

##脚本存放路径
spring.flyway.locations = classpath:db.migration

##当flyway第一次运行时,会在我们对应的数据库中新建一个记录脚本运行情况的
spring.flyway.table=flyway_schema_history

## 用户名
spring.flyway.user=root

## 密码
spring.flyway.password=root

## 数据库驱动
spring.flyway.driver-class-name=com.mysql.cj.jdbc.Driver

#设置flyway配置基线
spring.flyway.baseline-on-migrate=true

#迁移配置
spring.flyway.sql-migration-prefix=V
spring.flyway.sql-migration-separator=__
spring.flyway.sql-migration-suffixes=.sql

#编码
spring.flyway.encoding=UTF-8

#是否允许执行未按顺序的迁移脚本
spring.flyway.out-of-order=true

#日志
logging.level.org.flywaydb=debug

 

3、创建脚本

 4、启动项目,即可看到

 

 5、遇到的几个问题

1)org.flywaydb.core.api.FlywayException: Unsupported Database: MySQL 8.0

 一开始想用flyway最新的版本9.xx,启动后报错,查询后新版本不支持mysql

 flyway-core 8.2.1及以后的版本确实是不再支持MySQL

解决方式:

<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-mysql</artifactId>
</dependency>

2)Found non-empty schema(s) "PUBLIC" but no schema history table. Use baseline() or set baselineOnMigrate to true to initialize the schema history tabl

解决方法:

#设置flyway配置基线
spring.flyway.baseline-on-migrate=true
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值