2016-05-16 124 views
2

當我使用可重複的遷移時,我觀察到一些奇怪的Flyway行爲。文檔指出:Flyway可重複遷移 - 在版本化之前執行?

在單次遷移運行中,在執行完所有待執行的版本化遷移後,始終應用可重複遷移。

但在我看來,似乎可重複的遷移(這是重新創建一個數據庫視圖)失敗,因爲它是在版本遷移之前執行的。

遷飛信息數據,從遷移前: +-------------------+---------------------+---------------------+---------+ | 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*/` 

難道我做錯了什麼?
我使用飛路-行家-插件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/█` 

// EDIT1:

  1. outOfOrder設置爲假遷移仍然失敗,
  2. 乾淨+遷移似乎工作,但是這並不能解決問題,
  3. 我注意到了一件事 - 當我將數據庫回滾到版本201605041 43800000列表(浮動信息)末尾顯示可重複的遷移,但當20160504145200000遷移突然成功執行時,它們處於中間(如上表所示)。我不確定,如果這與實際的執行順序有任何關係。

回答

3

原來是Flyway中的一個錯誤:LINK - 它影響版本4.0 - 4.0.2並且已在4.0.3(Release notes)中修復。

我可以證實,現在它在空數據庫和現有數據庫上按預期工作。

0

這將是值得你改變outOfOrder屬性設置爲false,這樣的遷移可以在其定義的順序纔會發生。

如果您仍然看到問題,您是否也可以將cleanDisabled設置爲false,以便模式完全重建並報告您看到的內容。

以上兩種情況都會導致飛路以更確定的方式工作,從而讓其他人更加確定事件的順序。

+0

謝謝,我已經更新了OP。 –