即使指定了flyway.table,Flyway升级4.2.0-> 5.0.0迁移也会失败

时间:2019-04-23 22:19:16

标签: flyway

我正在更新一些在我们的应用程序中落后的Maven依赖项,并且遇到了从flyway-maven-plugin 4.2.0升级的问题,在该问题中,我们的reset和migration make命令以我可以的方式失败了。找不到任何有用的结果。

最初,我尝试从4.2.0迁移到5.2.4。当我无法解决我的错误时,我又回到了单个版本5.0.0。 按照5.0.0的发行说明,我向我的flyway- $ env.properties文件中添加了flyway.table=schema_version,并更新了我的Makefile命令以使用-Dflyway.configFiles=

当我尝试迁移现有的DB flyway时,尝试应用所有脚本,从而导致我们的初始db脚本违反约束。当无法运行schema_version表时,在运行初始脚本后尝试迁移空的DB flyway失败。

make命令执行以下操作:

@mvn -pl db flyway:repair \
    -Dflyway.url="jdbc:mysql://${FLYWAY_TARGET_HOST}:${FLYWAY_TARGET_PORT}/${FLYWAY_TARGET_DB}?useUnicode=true&characterEncoding=utf8&useSSL=false" \
    -Dflyway.password=${FLYWAY_TARGET_DB_PW} \
    -Dflyway.user=${FLYWAY_TARGET_DB_USER} \
    -Dflyway.configFiles="src/main/resources/config/flyway/${FLYWAY_CONFIG_FILENAME}.properties"
@mvn -pl db flyway:migrate \
    -Dflyway.url="jdbc:mysql://${FLYWAY_TARGET_HOST}:${FLYWAY_TARGET_PORT}/${FLYWAY_TARGET_DB}?useUnicode=true&characterEncoding=utf8&useSSL=false" \
    -Dflyway.password=${FLYWAY_TARGET_DB_PW} \
    -Dflyway.user=${FLYWAY_TARGET_DB_USER} \
    -Dflyway.configFiles="src/main/resources/config/flyway/${FLYWAY_CONFIG_FILENAME}.properties"

在空数据库上运行时,提供以下输出:

[INFO] --- flyway-maven-plugin:5.0.0:migrate (default-cli) @ db ---
[INFO] Flyway Community Edition 5.0.0 by Boxfuse
[INFO] Database: jdbc:mysql://localhost:3306/db_test (MySQL 5.7)
[INFO] Successfully validated 46 migrations (execution time 00:00.029s)
[INFO] Creating Schema History table: `db_test`.`schema_version`
[WARNING] Could not find schema history table `db_test`.`schema_version`, but found `db_test`.`schema_version` instead. You are seeing this message because Flyway changed its default for flyway.table in version 5.0.0 to flyway_schema_history and you are still relying on the old default (schema_version). Set flyway.table=schema_version in your configuration to fix this. This fallback mechanism will be removed in Flyway 6.0.0.
[INFO] Current version of schema `db_test`: << Empty Schema >>
[INFO] Migrating schema `db_test` to version 1.0 - DbBaseline
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.799 s
[INFO] Finished at: 2019-04-23T18:12:57-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:5.0.0:migrate (default-cli) on project db: org.flywaydb.core.internal.exception.FlywaySqlException: 
[ERROR] Unable to lock table `db_test`.`schema_version`

1 个答案:

答案 0 :(得分:0)

头脑清楚之后,问题出在我们的V1.0脚本中,特别是在创建表之前删除并重新创建模式。这导致在应用V1.0脚本后,无法生成flyway生成的表。

删除此行后,所有飞行作业均会正确执行。幸运的是,flyway:repair可以更正| Description | | ---------------- | | lurom ipsum [1] | | lurom ipsum [11] | | lurom ipsum [2] | | lurom ipsum [22] | 表中的校验和,而无需进行任何改动或手动进行数据库编辑。