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

相关推荐
To_OC23 分钟前
Next.js + Redis 构建笔记系统:Redis Hash 实战与性能优化
redis·后端·next.js
Super 含2 小时前
Android 启动优化(五):线程、GC 与 IO 为什么会拖慢启动?
java·服务器·数据库
ltl3 小时前
向量检索引擎选型:决策树、RAG 回链与开放问题
数据库
坚持学习前端日记3 小时前
Python SQLAlchemy ORM 从0到1精通实战手册(基础到复杂高阶)
数据库·python·oracle
灯澜忆梦3 小时前
【MySQL17】进阶篇 | InnoDB引擎
数据库·mysql
北斗落凡尘3 小时前
LangGraph 入门实战(11)--输出模式
后端·python·langchain
anxiao_m3 小时前
2026制造业云桌面选型攻略,不同生产场景适配方案汇总
大数据·网络·数据库
许彰午3 小时前
# 数据库配拦截器,不用改BPMN
数据库
demo007x4 小时前
Hermes-Agent 技术架构
前端·后端·agent
lv__pf4 小时前
redis【msb 2026金三银四redis上】
数据库·redis·缓存