首页 > 其他分享 >springboot - 整合flyway

springboot - 整合flyway

时间:2023-07-13 14:55:59浏览次数:39  
标签:8.2 springboot ## spring flyway 整合 org flywaydb

一、概念

官网:https://flywaydb.org/

数据库版本控制管理工具,通过集成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

 

标签:8.2,springboot,##,spring,flyway,整合,org,flywaydb
From: https://www.cnblogs.com/shirleyxueli/p/17550452.html

相关文章

  • 我开源了团队内部基于SpringBoot Web快速开发的API脚手架stater
    我们现在使用SpringBoot做Web开发已经比之前SprngMvc那一套强大很多了。但是用SpringBootWeb做API开发还是不够简洁有一些。每次WebAPI常用功能都需要重新写一遍。或者复制之前项目代码。于是我封装了这么一个抽出SpringBootWebAPI每个项目必备需要重复写的模块,和......
  • springboot下遇到的跨域问题
    后端跨域处理springboot项目注解@CrossOrigin实现WebMvcConfigurer接口中addCorsMappings(CorsRegistryregistry)方法配置CorsFilterfilter过滤器使用注意都可以单独使用,全部配置可能会导致不生效的问题addCorsMappings方法@Overridepublic......
  • springboot+vue前后端分离项目发布上线
    首先呢不用多说就是买阿里云服务器,但是呢,学生免费一个月。前端呢就是配置与后端端口 然后呢就是要打包:npmrunbuild把你的dist文件东西进行上传到服务器。后端springboot呢就是要打jar包上传。然后服务器是先去下载配置jdk,然后就是点击网站选择springboot项目最后一步呢......
  • jwt整合
    1.token问题目前方案是将token作为key,将登录的信息作为值存入到redis里面。2.使用jwt加入jwt之后就可以把redis去掉2.1.添加依赖2.2.创建工具类2.2.1.有效期30分钟2.2.2.令牌密钥暂时设置为1234562.2.3.创建jwt方法2.2.4.解析jwt方法......
  • SpringBoot中使用Netty开发WebSocket服务-netty-websocket-spring-boot-starter开源项
    场景SpringBoot+Vue整合WebSocket实现前后端消息推送:https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/114392573SpringCloud(若依微服务版为例)集成WebSocket实现前后端的消息推送:https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/114480731若依前后......
  • springboot 自定义整合caffeine 本地缓存
    1、自定义缓存配置类@Data@ConfigurationProperties(prefix="page.cache")publicclassPageCacheProperties{privateCaffeineConfigPropertiescaffeine=newCaffeineConfigProperties();//本地缓存配置privatePageCacheAsyncExecutorConfigpool=newP......
  • SpringBoot与Freemarker整合
    1.需要导入freemarker的pom文件;<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-freemarker</artifactId></dependency>2.需要在application.properties配置文件中配置一些freemarker的参数;serve.port......
  • 二维码简易实现 Vue+Springboot
    Vue:<template><div><img:src="database64"width="150px"/><div>注:请使用手机微信扫码,并于2分钟内绑定员工账号(二维码为账号独属,请勿分享)。</div></div></template><script>import{getQrCode}from"......
  • 4-基于SpringBoot实现SSMP整合
    1.整合JunitSpring整合JUnit的制作方式//加载spring整合junit专用的类运行器@RunWith(SpringJUnit4ClassRunner.class)//指定对应的配置信息@ContextConfiguration(classes=SpringConfig.class)publicclassAccountServiceTestCase{//注入你要测试的对象......
  • SpringBoot 如何处理 CORS 跨域?
    Springboot跨域问题,是当前主流web开发人员都绕不开的难题。但我们首先要明确以下几点跨域只存在于浏览器端,不存在于安卓/ios/Node.js/python/java等其它环境跨域请求能发出去,服务端能收到请求并正常返回结果,只是结果被浏览器拦截了。之所以会跨域,是因为受到了同源策略的限......