2017-07-03 82 views
0

我在Spring引導項目上工作,並使用Flyway進行數據庫遷移。 在dev-profile中工作時,我想用虛擬數據填充數據庫。 爲了有完全相同的初始數據我推翻了FlywayMigrationStrategy豆,使其遷移開始之前執行flyway.clean():爲什麼我的FlywayMigrationStrategy在兩次migrate.sql之後調用?

@Bean 
@Profile("dev") 
public FlywayMigrationStrategy cleanMigrateStrategy() { 
    FlywayMigrationStrategy strategy = new FlywayMigrationStrategy() { 
     @Override 
     public void migrate(Flyway flyway) { 
      flyway.clean(); 
      flyway.migrate(); 
     } 
    }; 

    return strategy; 
} 

我的移民文件夾中包含了幾個版本的遷移腳本,一個afterMigrate回調將數據添加到創建的表格的腳本。

enter image description here

現在的問題是,在afterMigrate.sql腳本被調用兩次,你可以從下面的日誌中看到:

2017-07-03 13:12:42.332 INFO 23222 --- [   main] o.f.core.internal.command.DbClean  : Successfully cleaned schema "PUBLIC" (execution time 00:00.031s) 
2017-07-03 13:12:42.397 INFO 23222 --- [   main] o.f.core.internal.command.DbValidate  : Successfully validated 4 migrations (execution time 00:00.044s) 
2017-07-03 13:12:42.413 INFO 23222 --- [   main] o.f.c.i.metadatatable.MetaDataTableImpl : Creating Metadata table: "PUBLIC"."schema_version" 
2017-07-03 13:12:42.428 INFO 23222 --- [   main] o.f.core.internal.command.DbMigrate  : Current version of schema "PUBLIC": << Empty Schema >> 
2017-07-03 13:12:42.430 INFO 23222 --- [   main] o.f.core.internal.command.DbMigrate  : Migrating schema "PUBLIC" to version 1 - create users 
2017-07-03 13:12:42.449 INFO 23222 --- [   main] o.f.core.internal.command.DbMigrate  : Migrating schema "PUBLIC" to version 2 - create address 
2017-07-03 13:12:42.464 INFO 23222 --- [   main] o.f.core.internal.command.DbMigrate  : Migrating schema "PUBLIC" to version 3 - create patient case 
2017-07-03 13:12:42.475 INFO 23222 --- [   main] o.f.core.internal.command.DbMigrate  : Migrating schema "PUBLIC" to version 4 - state machine 
2017-07-03 13:12:42.498 INFO 23222 --- [   main] o.f.core.internal.command.DbMigrate  : Successfully applied 4 migrations to schema "PUBLIC" (execution time 00:00.086s). 
2017-07-03 13:12:42.499 INFO 23222 --- [   main] o.f.c.i.c.SqlScriptFlywayCallback  : Executing SQL callback: afterMigrate 
2017-07-03 13:12:42.502 INFO 23222 --- [   main] o.f.c.i.c.SqlScriptFlywayCallback  : Executing SQL callback: afterMigrate 
2017-07-03 13:12:42.917 INFO 23222 --- [   main] o.s.j.e.a.AnnotationMBeanExporter  : Registering beans for JMX exposure on startup 

如果我刪除flyway.clean()函數調用它只被調用一次。

有人可以告訴我爲什麼當我打電話給flyway.clean()和flyway.migrate()以及如何防止第二次調用時,它被調用兩次?

回答

相關問題