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文件已成功执行。