2014-02-27 99 views

回答

8

有沒有簡單的方法來告訴使用公共API是否MigrateUp方法會做或不。

不過,也有解決這個多個「其他」方式依賴於FluentMigrator的內部:從MigrationRunner

  • 導出,覆蓋ApplyMigrationUp方法,該方法被調用每一個移民被應用的時候,和跟蹤/日誌應用遷移

  • 創建自定義IAnnouncer實現,配置FluentMigrator通過IRunnerContext並在播音員Say方法檢查使用它的message參數包含文本"migrated",這意味着已應用遷移步驟。

  • 看未決遷移運行MigrateUp,如果你能得到一個MigrationRunner參考之前您可以:
MigrationRunner runner = ... // get a reference to the runner 
    if (runner.MigrationLoader.LoadMigrations() // get all the migrations 
      .Any(pair => !runner.VersionLoader 
           .VersionInfo.HasAppliedMigration(pair.Key))) 
      // check which migrations have been applied 
    { 
     // there are pending migrations, do your logic here 
    } 
+0

幹得漂亮。最後一點工作就像一個魅力。 – OnResolve