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

相关推荐
懒鸟一枚9 分钟前
为什么 useradd -rs /bin/false service 创建的用户无法用 su 切换?
linux·服务器·数据库
爱喝热水的呀哈喽17 分钟前
hypermesh两个网格参数解析
服务器·数据库·mysql
万亿少女的梦16826 分钟前
基于Spring Boot的楚雄旅游景区门票售卖系统设计与实现
java·spring boot·mysql·vue·系统设计
雨师@31 分钟前
go语言项目--实例化(图书管理)--005
开发语言·后端·golang
Aspiresky42 分钟前
探索Rust语言之引用
开发语言·后端·rust
IvorySQL1 小时前
PG 技术日报|2026-07-03
数据库·postgresql·开源
冰暮流星1 小时前
flask之app.py讲解
后端·python·flask
长孙豪翔1 小时前
引发事件的问题
java·linux·数据库
吴声子夜歌1 小时前
SQL进阶——HAVING子句
数据库·sql
程序员契奇2 小时前
Tools工具使用
人工智能·后端