Flyway 没有执行脚本

far*_*ahm 3 flyway spring-boot

我有带有 Flyway 的 Spring Boot 应用程序。

我有以下 sql 脚本:

src/main/resources/db/migration/V1__init.sql

但脚本没有执行。

application.properties文件中我有:

spring.datasource.url = jdbc:mysql://localhost:3306/carorderprocess?useSSL=false
spring.datasource.username = root
spring.datasource.password = ...
spring.flyway.baselineOnMigrate = true
Run Code Online (Sandbox Code Playgroud)

当我运行应用程序时,在数据库中我只看到:

mysql> select * from flyway_schema_history;
+----------------+---------+-----------------------+----------+-----------------------+----------+--------------+---------------------+----------------+---------+
| installed_rank | version | description           | type     | script                | checksum | installed_by | installed_on        | execution_time | success |
+----------------+---------+-----------------------+----------+-----------------------+----------+--------------+---------------------+----------------+---------+
|              1 | 1       | << Flyway Baseline >> | BASELINE | << Flyway Baseline >> |     NULL | root         | 2019-11-19 10:47:52 |              0 |       1 |
+----------------+---------+-----------------------+----------+-----------------------+----------+--------------+---------------------+----------------+---------+
Run Code Online (Sandbox Code Playgroud)

所以脚本没有执行,为什么?

Tin*_*nki 5

此脚本不会运行,因为提供的文件名版本不高于flyway_schema_history表中存储的最大版本。您可以执行两种解决方案:

  1. 清空flyway_schema_history桌子
  2. 将您的文件重命名为V2__init.sql(推荐解决方案)

然后只需重新启动您的 Spring Boot 应用程序,即可立即应用更改

一个注意事项:第一种解决方案可能需要移除spring.flyway.baselineOnMigrate = true财产。我也会考虑你是否真的需要它。可以在这里找到它的作用