java - 如何让 FlyWay 运行我的迁移? "Schema is up to date. No migration necessary."

标签 java spring-boot flyway

我有一个现有的数据库。我创建了两个迁移

$ ls src/main/resources/db/migration/
V1__create_stats.sql  V2__create_sources.sql

我在 application.properties 中设置了以下内容

# Prevent complaints when starting migrations with existing tables.
flyway.baselineOnMigrate = true

否则会报错 org.flywaydb.core.api.FlywayException: Found non-empty schemagalaxybadgewithout metadata table!使用 baseline() 或将 baselineOnMigrate 设置为 true 来初始化元数据表。

当我尝试启动应用程序时,它会跳过迁移并且不会执行它们!我在 MySQL 中使用 show tables; 并发现它们不存在!

>mvn spring-boot:run
...
2018-05-09 18:43:03.671  INFO 24520 --- [  restartedMain] o.f.core.internal.util.VersionPrinter    : Flyway 3.2.1 by Boxfuse
2018-05-09 18:43:04.420  INFO 24520 --- [  restartedMain] o.f.c.i.dbsupport.DbSupportFactory       : Database: jdbc:mysql://localhost:3306/galaxybadge (MySQL 5.5)
2018-05-09 18:43:04.486  INFO 24520 --- [  restartedMain] o.f.core.internal.command.DbValidate     : Validated 0 migrations (execution time 00:00.030s)
2018-05-09 18:43:04.704  INFO 24520 --- [  restartedMain] o.f.c.i.metadatatable.MetaDataTableImpl  : Creating Metadata table: `galaxybadge`.`schema_version`
2018-05-09 18:43:05.116  INFO 24520 --- [  restartedMain] o.f.core.internal.command.DbBaseline     : Schema baselined with version: 1
2018-05-09 18:43:05.145  INFO 24520 --- [  restartedMain] o.f.core.internal.command.DbMigrate      : Current version of schema `galaxybadge`: 1
2018-05-09 18:43:05.146  INFO 24520 --- [  restartedMain] o.f.core.internal.command.DbMigrate      : Schema `galaxybadge` is up to date. No migration necessary.

我看了this answer但它没有帮助,似乎给出了错误的属性名称。这是它创建的 schema_version 表。

> select * from schema_version;
+--------------+----------------+---------+-----------------------+----------+-----------------------+----------+--------------+---------------------+----------------+---------+
| version_rank | installed_rank | version | description           | type     | script                | checksum | installed_by | installed_on        | execution_time | success |
+--------------+----------------+---------+-----------------------+----------+-----------------------+----------+--------------+---------------------+----------------+---------+
|            1 |              1 | 1       | << Flyway Baseline >> | BASELINE | << Flyway Baseline >> |     NULL | root         | 2018-05-09 18:43:05 |              0 |       1 |
+--------------+----------------+---------+-----------------------+----------+-----------------------+----------+--------------+---------------------+----------------+---------+

Spring Boot 1.5.6,FlyWay Core 3.2.1

Spring docs - FlyWay docs

最佳答案

好的,我找到了这个https://flywaydb.org/documentation/existing

但没有跟进。相反,我将迁移从 V1__*V2__* 移到了 V2...V3...并将生产模式下载到 V1__initialize.sql 中。

mysqldump -h project.us-east-1.rds.amazonaws.com -u username -p --no-data --skip-add-drop-table --compact --skip-set-charset databasename > V1__initialize.sql

然后,当我运行 Spring mvn spring-boot:run 时,它会运行迁移。

(嗯,实际上有很多 SQL 调试,我不得不多次删除表并删除 schema_verion 中的行并从 target/.. 中删除旧文件名。 ./migration/ 但那是另一回事了。)

我相信有可能设置

flyway.baselineVersion=0

并根据此处的信息跳过 SQL 转储(初始化):https://flywaydb.org/documentation/configfiles .但是,为 future 的开发人员提供架构似乎是正确的方法。

我仍然不明白为什么它没有从原始问题运行 V2__... 迁移。如果它从 1 开始,那么迁移 2 仍然可以运行。如果它按预期工作,那么我可能会更快地理解问题。

关于java - 如何让 FlyWay 运行我的迁移? "Schema is up to date. No migration necessary.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50263305/

相关文章:

java - 如何多次更改 JLabel 文本?

spring - 不能将 PowerMockRunner 与 SpringBootTest 一起使用

java - Spring 声明式事务中的传播(选择正确)问题

java - 使用 Neo4j 和 Spring 进行数据库迁移

java - Spring Boot 2.5.1 服务不会在 System.exit(0) 上停止

java.text.SimpleDateFormat 闰年

java - 在 Google Cloud End Points 中一次插入多个相同类型的记录

java - Java 中的 PreparedStatement 删除

java - Spring Boot 与 GraphQL - 架构问题

postgresql - 在 Jenkins 中使用 docker Container 链接