【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文件首次启动后不要再修改此文件。

相关推荐
Gopher_HBo几秒前
moby-daemon-config配置
后端
拉斯特当思几秒前
设备总掉线却复现不了?把弱网“造“出来:tcconfig 五种网络故障模拟实战
后端
RainCity4 分钟前
Java Swing 自定义组件库分享(十五)
java·笔记·后端
程序员麻辣烫5 分钟前
Memory向量记忆系统4-文本向量化
后端·aigc
Java编程爱好者7 分钟前
Java 并发锁体系全解:从 synchronized、Lock 到 AQS 底层原理与源码深度剖析
后端
程序员天天困7 分钟前
Java 项目用 Single-flight 一招终结 AI 接口重复调用
redis·后端
farerboy10 分钟前
23-Java 构造函数
java·后端
程序员麻辣烫17 分钟前
Memory向量记忆系统3-数据选取
后端·aigc
程序员麻辣烫19 分钟前
Memory向量记忆系统2-SQLite
后端·aigc
阳光是sunny24 分钟前
LangGraph高级教程:Multi Schema多状态管理详解
前端·人工智能·后端