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

相关推荐
xcLeigh6 小时前
IoTDB 数据导入全攻略:工具、自动加载与 Load SQL 详解
数据库·sql·工具·iotdb·数据导入·loadsql
编程小白gogogo6 小时前
苍穹外卖图片不显示解决教程
java·spring boot
上进小菜猪7 小时前
基于 YOLOv8 的水体污染目标检测系统 [目标检测完整源码]
后端
清漠2338 小时前
win11“网络和Internet“中无“以太网“这个选项解决记录
服务器·网络·数据库
那个松鼠很眼熟w9 小时前
3.Statement对象概述,以及Statement的弊端
数据库
山岚的运维笔记10 小时前
SQL Server笔记 -- 第72章:隔离级别与锁定
数据库·笔记·后端·sql·microsoft·sqlserver
硅基动力AI10 小时前
如何判断一个关键词值不值得做?
java·前端·数据库
新缸中之脑11 小时前
从零实现AI代理的长期记忆
数据库·人工智能
清水白石00812 小时前
Fixture 的力量:pytest fixture 如何重新定义测试数据管理
数据库·python·pytest
想用offer打牌12 小时前
一站式了解接口防刷(限流)的基本操作
java·后端·架构