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

相关推荐
ClouGence11 小时前
开源数据库管理工具 CloudDM 新版本发布,支持 OpenSearch、IoTDB 数据源
数据库·开源
徐小黑ACG12 小时前
Redis-基础
数据库·redis·缓存
火山引擎开发者社区12 小时前
案例实践 | 让 Agent 读懂业务口径:ContextSearch 在广告数据查询中的实践
数据库
学长毕设13 小时前
基于SpringBoot的野生动物公益保护平台设计与实现-附源码
java·spring boot·后端
10年前端老司机13 小时前
Milvus 8种检索能力实践
数据库·python·agent
梦里寻码14 小时前
我用 NestJS + Vue3 写了一套完整的研发管理系统(58 表 / 229 API / 130 项断言,全开源
前端·后端·算法
鶴哥只手遮天14 小时前
《Redis 8.10.3 深度剖析》系列 ·第 10 章 Hash 一:`listpack`、`hashtable` 与 `LISTPACK_EX`
redis·后端·开源
Decay__14 小时前
14_MySQL 高可用与容灾架构 —— MGR / InnoDB Cluster / Keepalived+VIP / 双主 / 读写分离 / 两地三中心
运维·数据库·sql·mysql·架构
johnjincaaaa14 小时前
WebAssembly 逆向实战:从 0 搞懂猿人学第 15 题
后端
Gopher_HBo14 小时前
Go CPU 剖析:四角色白话机制 + 实测实验
后端