Flyway conditional db migration

非 Y 不嫁゛ 提交于 2021-02-10 04:15:21

问题


I'm trying to use flyway, but I have a scenario that does not know how to resolve:

When I apply the STANDARD scripts, I have to run V1.0__create_table_TAB1.sql When I apply the scripts to customer1, the TAB1 table is a view, and so I have to run V1.0__create_view_TAB1_to_schema1.sql.

Practically:

└── 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

The scripts of sql_common folder should always be applied, but the V1.0 (create table TAB1), if I apply to the customer1 script should not be applied. In its place is to be applied V1.0__create_view_TAB1_to_schema1.sql

How can I handle prevents this case?


回答1:


Use the following structure:

└── 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

in combination with Flyway.setLocations().

  • Regular: 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");

This way there will be exactly 1 migration with v1.0 per case.



来源:https://stackoverflow.com/questions/42365725/flyway-conditional-db-migration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!