Springboot整合flyway管理数据库脚本

文章目录

    • 引入flyway依赖
    • 新增flyway配置项
    • 增加要执行的sql文件
    • 启动springboot应用

Flyway 是一个开源的数据库迁移工具。它强烈支持简单和约定而不是配置。

https://flywaydb.org/documentation/

引入flyway依赖

<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-core</artifactId>
    <version>5.2.4</version>
</dependency>

新增flyway配置项

spring:
  flyway:
    enabled: true
    clean-disabled: true
    locations: classpath:/sql
    table: flyway_schema_history
    baseline-on-migrate: true
    schemas: xxx(项目中数据库名称)
    validate-on-migrate: true

增加要执行的sql文件

在这里插入图片描述

启动springboot应用

查看数据库flyway_schema_history表数据,看到sql文件已成功执行。
在这里插入图片描述

你可能感兴趣的:(Java,spring,boot,数据库,后端)