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

相关推荐
逸风尊者3 分钟前
开发也能看懂的大模型:聚类
人工智能·后端·trae
小李是个程序16 分钟前
分层解耦(Controller,Service,Dao)
java·开发语言·spring boot·后端
帧栈21 分钟前
开发避坑短篇(12):达梦数据库TIMESTAMP字段日期区间查询实现方案
数据库·sql·oracle
golitter.24 分钟前
python中高效构建提示词
前端·数据库·python
小醉你真好36 分钟前
「Spring Boot + MyBatis-Plus + MySQL 一主两从」读写分离实战教程
spring boot·mysql·mybatis
都叫我大帅哥42 分钟前
Java世界的“门神”——API Gateway(API网关)
java·spring boot·spring cloud
Elastic 中国社区官方博客1 小时前
使用 Elasticsearch 和 AI 构建智能重复项检测
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
Victor3561 小时前
MySQL(172)如何进行MySQL的全局变量设置?
后端
fouryears_234171 小时前
RabbitMQ 的死信队列完整指南 (With Spring Boot)
spring boot·rabbitmq·java-rabbitmq
Victor3561 小时前
MySQL(171)如何使用MySQL的INFORMATION_SCHEMA?
后端