【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 分钟前
MongoDB
数据库·mongodb
oyzz1204 分钟前
Spring EL 表达式的简单介绍和使用
java·后端·spring
m0_743623926 分钟前
React 自定义 Hook 的命名规范与调用规则详解
jvm·数据库·python
古城小栈32 分钟前
GORM 操作 PostgreSQL 高级类型
数据库·postgresql
ward RINL36 分钟前
redis分页查询
数据库·redis·缓存
Treh UNFO37 分钟前
Redis-配置文件
数据库·redis·oracle
zhenxin012238 分钟前
【wiki知识库】07.用户管理后端SpringBoot部分
spring boot·后端·状态模式
iNgs IMAC39 分钟前
Redis之Redis事务
java·数据库·redis
oLLI PILO39 分钟前
Redis连接池
数据库·redis·缓存
码事漫谈1 小时前
OpenSpec 简明教程
后端