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

相关推荐
云技纵横8 分钟前
@Transactional 里套 REQUIRES_NEW,为什么会把连接池耗尽?
后端·面试
tcdos13 分钟前
不止扫码 — 微信生态深度融合(登录 + 支付 + 消息)
后端·微信小程序
程序员cxuan16 分钟前
Anthropic 大面积封号,连大 V 都忍不了开喷了。
人工智能·后端·程序员
MacroZheng27 分钟前
短短几天,暴涨2.8万Star!又一款编程神器开源!
java·人工智能·后端
PinkSun31 分钟前
平台线程池用了3年很顺手,换成虚拟线程后我后悔了
后端
达达尼昂34 分钟前
Claude : 如何设计可控的agent-loops
前端·人工智能·后端
lambdax36 分钟前
Celery 心跳任务内存膨胀排查与修复全记录
后端
SamDeepThinking40 分钟前
函数式编程:用BiFunction消除多类型分支的代码重复
java·后端·面试
IT_陈寒1 小时前
Redis持久化丢失数据的坑,这次终于被我填平了
前端·人工智能·后端
葫芦和十三2 小时前
图解 MongoDB 24|分片为什么存在:垂直扩容的天花板
后端·mongodb·agent