【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 分钟前
一步步实现字符串计算器:从「转整数」到「带括号与优化」
javascript·后端·算法
离开地球表面_998 分钟前
金三银四程序员跳槽指南:从简历到面试再到 Offer 的全流程准备
前端·后端·面试
UrbanJazzerati8 分钟前
Scrapling入门指南:零基础也能学会的网页抓取神器
后端·面试
张洪权8 分钟前
mysql + nest.js 加锁 搞并发问题
后端
随逸1779 分钟前
《Milvus向量数据库从入门到实战,手把手搭建语义检索系统》
数据库
郡杰10 分钟前
MyBatisPlus
后端
beata11 分钟前
Java基础-18:Java开发中的常用设计模式:深入解析与实战应用
java·后端
Qlly17 分钟前
DDD 架构为什么适合 MCP Server 开发?
人工智能·后端·架构
苏三说技术35 分钟前
Prompt、Agent、Function Call、Skill、MCP,傻傻分不清楚?
后端
小码哥_常1 小时前
Spring Boot接口幂等保护:一个注解开启数据一致性守护
后端