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

相关推荐
Teable任意门互动几秒前
中小企业进销存实战:Teable多维表格从零搭建高效库存管理系统
开发语言·数据库·excel·飞书·开源软件
Y001112361 分钟前
Day7-MySQL-约束
数据库·sql·mysql
tuyanfei4 分钟前
Spring 简介
java·后端·spring
ZhengEnCi5 分钟前
J0A-JPA持久化技术专栏链接目录
java·数据库
智能工业品检测-奇妙智能5 分钟前
openclaw使用硅基流动免费模型
服务器·人工智能·spring boot·电商·openclaw
代码探秘者7 分钟前
【大模型应用】2.RAG详细流程
java·开发语言·人工智能·后端·python
神奇小汤圆9 分钟前
网易一面:KAFKA写入数据时是先写Leader还是先写Follower?
后端
baizhigangqw12 分钟前
Spring Boot spring.factories文件详细说明
spring boot·后端·spring
爱吃土豆的马铃薯ㅤㅤㅤㅤㅤㅤㅤㅤㅤ16 分钟前
DB-GPT 和 Dify 区别
数据库·gpt
Insist75317 分钟前
kingbase数据库--指定备份集恢复
数据库