2017-02-21 155 views
1

我試圖用飛路,但我有一個場景,不知道如何解決:遷飛條件DB遷移

當我申請的標準腳本,我要運行V1.0__create_table_TAB1.sql 當我將腳本應用到customer1,TAB1表是一個視圖,所以我必須運行V1.0__create_view_TAB1_to_schema1.sql。

實際上:

└── sql 
    ├── sql_common 
    │ ├── V0.0 __.... sql 
    │ └── V1.0__create_table_TAB1.sql 
    ├── sql_customer1 
    │ └── V1.0__create_view_TAB1_to_schema1.sql 
       └── sql_customer2 
         └── V1.0__create_view_TAB1_to_schema2.sql 

sql_common文件夾的腳本應該總是被應用,但V1.0(創建表TAB1),如果我申請到customer1表腳本不宜應用。 代替它應用V1.0__create_view_TAB1_to_schema1.sql

我該如何處理防止這種情況?

回答

1

使用以下結構:

└── sql 
    ├── sql_common 
    │ └── V0.0 __.... sql 
    ├── sql_regular 
    │ └── V1.0__create_table_TAB1.sql 
    ├── sql_customer1 
    │ └── V1.0__create_view_TAB1_to_schema1.sql 
       └── sql_customer2 
         └── V1.0__create_view_TAB1_to_schema2.sql 

結合Flyway.setLocations()。

  • 常規:flyway.setLocations("filesystem:sql/sql_common", "filesystem:sql/sql_regular");
  • customer1表: flyway.setLocations("filesystem:sql/sql_common", "filesystem:sql/sql_customer1");
  • 的customer2: flyway.setLocations("filesystem:sql/sql_common", "filesystem:sql/sql_customer2");

這樣會有用每箱V1.0正好1遷移。