【springboot】【flyway】数据库版本控制

这里写目录标题

pom.xml

本项目 spring-boot版本2.3.0

注意根据后面实际路径配置<include>**/**/*.sql</include>

xml 复制代码
......
<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-core</artifactId>
    <version>5.2.1</version>
</dependency>
......
<resource>
   <directory>src/main/resources</directory>
    <includes>
        <include>**/*.yml</include>
        <include>**/*.properties</include>
        <include>**/*.xml</include>
        <include>**/**/*.sql</include>
    </includes>
    <filtering>false</filtering>
</resource>
......

application.yml

locations: classpath:db/migration可改为自定义路径

yaml 复制代码
spring:
  flyway:
    enabled: true
    table: flyway_schema_history
    encoding: UTF-8
    baseline-on-migrate: true
    locations: classpath:db/migration
    sql-migration-prefix: V
    sql-migration-suffixes: .sql
    validate-on-migrate: true
    check-location: true
    clean-disabled: true

sql文件

相关sql文件放置在resources目录下,根据spring.flyway.locations新建文件夹db和子文件夹migration,创建相关VXXX__XXXX.sql

启动

如果数据库没有flyway_schema_history会自动创建,.sql文件首次启动后不要再修改此文件。

相关推荐
金銀銅鐵2 小时前
为什么枚举类中可以定义抽象方法
java·后端·ai编程
陈随易3 小时前
Vue 编译器换掉 source map,快了三四成
前端·后端·程序员
叼烟扛炮3 小时前
Linux 学习笔记(五十六):IO 多路复用初探——select 的“三宗罪”
linux·服务器·数据库·笔记·学习·php
txxzjmzlh4 小时前
SpringBoot 统⼀功能处理
java·spring boot·后端
.痞老板.5 小时前
mysql初阶--数据库基础
数据库·mysql
nice_lcj5206 小时前
Java Lambda 表达式入门:怎么写、怎么用、常用方法有哪些
java·开发语言·后端·面试
城北徐宫6 小时前
MySQL约束条件一览
数据库·mysql
IT_陈寒7 小时前
Redis大key删除为什么会导致服务卡顿?我的线上事故复盘
前端·人工智能·后端
系统集成-鹰翔7 小时前
ERP图片改名后仍命中识别缓存:缓存键、十分钟到期与调用计数
javascript·经验分享·后端
用户8356290780517 小时前
使用 Python 在 Excel 中添加和自定义迷你图
后端·python