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

相关推荐
用户1512905452209 分钟前
Langfuse-开源AI观测分析平台,结合dify工作流
后端
南囝coding14 分钟前
Claude Code 从入门到精通:最全配置指南和工具推荐
前端·后端
会开花的二叉树1 小时前
彻底搞懂 Linux 基础 IO:从文件操作到缓冲区,打通底层逻辑
linux·服务器·c++·后端
lizhongxuan1 小时前
Spec-Kit 使用指南
后端
爱吃烤鸡翅的酸菜鱼1 小时前
【Spring】原理解析:Spring Boot 自动配置
java·spring boot
十八旬1 小时前
苍穹外卖项目实战(day7-1)-缓存菜品和缓存套餐功能-记录实战教程、问题的解决方法以及完整代码
java·数据库·spring boot·redis·缓存·spring cache
会豪1 小时前
工业仿真(simulation)--发生器,吸收器,缓冲区(2)
后端
SamDeepThinking1 小时前
使用Cursor生成【财务对账系统】前后端代码
后端·ai编程·cursor
饭碗的彼岸one1 小时前
C++ 并发编程:异步任务
c语言·开发语言·c++·后端·c·异步
会豪1 小时前
工业仿真(simulation)--仿真引擎,离散事件仿真(1)
后端