database-migration - Flyway 可重复迁移 - 在版本化迁移之前执行?

标签 database-migration flyway

在使用可重复迁移时,我观察到一些奇怪的 Flyway 行为。文件指出:

Within a single migration run, repeatable migrations are always applied last, after all pending versioned migrations have been executed.

但就我而言,可重复迁移(正在重新创建数据库 View 之一)似乎失败,因为它是在版本化迁移之前执行的。

迁徙路线信息数据,来自迁移之前: +-------------------+---------------------+---------------------+---------+ | Version | Description | Installed on | State | +-------------------+---------------------+---------------------+---------+ | 1 | Initial | | <Baseln | | 2 | ███████████████████ | | <Baseln | | 5 | Initial data | | <Baseln | | 6 | Initial sample data | 2016-04-29 14:21:13 | Success | | 20160422002600000 | ███████████████████ | 2016-04-29 14:33:48 | Success | | 20160422003400000 | ███████████████████ | 2016-04-29 14:33:48 | Success | | 20160422004700000 | ███████████████████ | 2016-04-29 14:33:48 | Success | | 20160428152800000 | ███████████████████ | 2016-04-29 14:33:48 | Success | | 20160428163300000 | ███████████████████ | 2016-04-29 14:33:48 | Success | | 20160428171300000 | ███████████████████ | 2016-04-29 14:33:48 | Success | | | ProblematicView | 2016-04-29 14:33:48 | Outdate | | | Reports | 2016-04-29 14:33:49 | Success | | | OtherView | 2016-04-29 14:33:49 | Success | | 20160429115100000 | ███████████████████ | 2016-04-29 14:37:10 | Success | | 20160429160100000 | ███████████████████ | 2016-05-16 11:54:24 | Success | | 20160501090500000 | ███████████████████ | 2016-05-16 11:54:24 | Success | | 20160504111600000 | ███████████████████ | 2016-05-16 11:54:24 | Success | | 20160504120400000 | ███████████████████ | 2016-05-16 11:54:24 | Success | | 20160504143800000 | ███████████████████ | 2016-05-16 11:54:24 | Success | | 20160504145200000 | ███████████████████ | 2016-05-16 11:54:25 | Success | | 20160504161600000 | ███████████████████ | | Pending | | 20160506110300000 | ███████████████████ | | Pending | | 20160506162300000 | ███████████████████ | | Pending | | 20160506232000000 | ███████████████████ | | Pending | | 20160508144100000 | ███████████████████ | | Pending | | 20160509192400000 | ███████████████████ | | Pending | | 20160511160000000 | ███████████████████ | | Pending | | 20160511163659000 | ███████████████████ | | Pending | | 20160511163700000 | A newly_created_col | | Pending | | 20160511170000000 | ███████████████████ | | Pending | | 20160512112100000 | ███████████████████ | | Pending | | 20160512170500000 | ███████████████████ | | Pending | | 20160513134900000 | ███████████████████ | | Pending | +-------------------+---------------------+-------------------------------+

和迁移日志:

[INFO] Database: jdbc:sqlserver://█:1433;authenticationScheme=nativeAuthentication;xopenStates=false;sendTimeAsDatetime=true;trustServerCertificate=false;sendStringParametersAsUnicode=true;selectMethod=direct;responseBuffering=adaptive;packetSize=8000;multiSubnetFailover=false;loginTimeout=15;lockTimeout=-1;lastUpdateCount=true;encrypt=false;disableStatementPooling=true;databaseName=█;applicationName=Microsoft JDBC Driver for SQL Server;applicationIntent=readwrite; (Microsoft SQL Server 11.0)
[INFO] Successfully validated 33 migrations (execution time 00:00.052s)
[INFO] SQLServer does not support setting the schema for the current session. Default schema NOT changed to dbo
[INFO] Current version of schema [dbo]: 20160504145200000
[WARNING] outOfOrder mode is active. Migration of schema [dbo] may not be reproducible.
[INFO] Migrating schema [dbo] with repeatable migration ProblematicView
[ERROR] Migration of schema [dbo] with repeatable migration ProblematicView failed! Changes successfully rolled back.
[INFO] SQLServer does not support setting the schema for the current session. Default schema NOT changed to dbo
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.550s
[INFO] Finished at: Mon May 16 12:40:49 CEST 2016
[INFO] Final Memory: 10M/243M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:4.0.1:migrate (migrate-¦) on project ¦-db: org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException:
[ERROR] Migration R__ProblematicView.sql failed
[ERROR] ------------------------------------------------
[ERROR] SQL State  : S0001
[ERROR] Error Code : 207
[ERROR] Message    : Invalid column name 'newly_created_column'. /*<-- column created in V20160511163700000*/`

我做错了什么吗?
我正在使用 Flyway-maven-plugin 4.0.1(也在 4.0 上进行了测试),具有以下属性:

Maven:
<cleanDisabled>true</cleanDisabled>
<outOfOrder>true</outOfOrder>
<table>schema_version</table>
<repeatableSqlMigrationPrefix>R</repeatableSqlMigrationPrefix>
<sqlMigrationPrefix>V</sqlMigrationPrefix>
Config file:
flyway.user=flyway
flyway.password=█
flyway.url=jdbc:sqlserver://█;databasename=█
flyway.locations=filesystem:flyway/upgrade/█`

//编辑1:

  1. outOfOrder 设置为 false 时,迁移仍然失败,
  2. clean + migrate 似乎有效,但这并不能完全解决问题,
  3. 我还注意到一件事 - 当我将数据库回滚到版本 20160504143800000 可重复迁移时,会显示在列表末尾(flyway 信息),但是当 20160504145200000 迁移成功执行时,它们突然出现在中间(如上表所示)。我不确定这是否与实际执行顺序有关。

最佳答案

事实证明这是 Flyway 中的一个错误:LINK - 它影响版本 4.0 - 4.0.2,并已在 4.0.3 中修复 ( Release notes )。

我可以确认现在它在空数据库和现有数据库上都能按预期工作。

关于database-migration - Flyway 可重复迁移 - 在版本化迁移之前执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37253444/

相关文章:

PostgreSQL 中的 MySQL SET 类型?

php - 连接到远程数据库失败: Laravel application

spring-boot - 使用 Flyway 和 Spring Boot 进行基线迁移

java - 使用 Spring Boot 运行基于 Flyway Java 的回调

java - @MockBean 似乎重新运行上下文创建并在 Migrate.sql 之后失败

django - Django删除了迁移目录

ruby-on-rails - 有没有办法不在rails中生成迁移文件

ruby-on-rails - 如何更改 rails 迁移文件中的主键?

flyway - "compress"Flyway迁移的任何方法?

java - Flyway使用java类对sql文件进行排序