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

相关推荐
九河云7 小时前
TOS + 数字孪生:集装箱码头的智能进化密码
大数据·服务器·网络·数据库·数字化转型
间彧7 小时前
Spring Boot默认支持Logback的原因分析
后端
ezl1fe7 小时前
第零篇:把 Agent 跑起来的最小闭环
人工智能·后端·agent
文心快码BaiduComate7 小时前
文心快码Comate3.5S更新,用多智能体协同做个健康管理应用
前端·人工智能·后端
爆更小哇7 小时前
统一功能处理
java·spring boot
我是天龙_绍7 小时前
mybatis-plus 设置 数据库的字段自动填充
后端
Rust菜鸡7 小时前
在你的Rust类型里生成TypeScript的bindings!
后端
间彧7 小时前
Logback、Log4j与SLF4J的区别与选型指南
后端
手握风云-7 小时前
MySQL数据库精研之旅第十九期:存储过程,数据处理的全能工具箱(二)
数据库·mysql
间彧7 小时前
Logback详解与Spring Boot项目实战指南
后端