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

相关推荐
Hamm7 小时前
前端转Java+AI全栈?那我推荐几个实战开源项目给你
前端·后端·全栈
冷凝娇7 小时前
【MySQL】2026总结(二)
数据库·mysql
凤山老林7 小时前
Spring Boot 定时任务进阶:动态 Cron 与集群防重实战
java·spring boot·后端·定时任务·集群定时任务
aaa小葵8 小时前
LangGraph
数据库·人工智能
站大爷IP8 小时前
被 `asyncio.gather` 和 `wait` 坑惨了:异常处理的天壤之别
后端
wWYy.8 小时前
Mysql:Read View
数据库·mysql
张龙6878 小时前
Docker 镜像瘦身实战:从 1.2GB 到 128MB,我踩过的 7 个坑和一套可复制的方法论
运维·后端·docker
lizhongxuan9 小时前
工程技术:在智能体优先的世界中利用 Codex(转)
后端
—Miss. Z—9 小时前
存储过程、用户定义函数、触发器和游标
数据库·mysql
Dear~yxy10 小时前
MySQL企业级实战
数据库·mysql