How to set up liquibase in Spring for multiple data sources?

前端 未结 5 1832
醉话见心
醉话见心 2020-12-25 07:59

I need to set up liquibase for two datasources in Spring, at the moment it seems that only one liquibase set up is possib

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-25 08:50

    You can also run multiple liquibase instance (i.e. not only limit to a primary and a secondary).

    e.g. Your configuration java can have:

    @Bean
    @ConfigurationProperties(prefix = "liquibase1")
    ...
    @Bean
    @ConfigurationProperties(prefix = "liquibase2")
    ...
    @Bean
    @ConfigurationProperties(prefix = "liquibase3")
    

    Your application.property can have:

    liquibase1.default-schema=schemaA
    ...
    liquibase2.default-schema=schemaB
    ...
    liquibase3.default-schema=schemaC
    ...
    

    And (excitingly), these springLiquibase instances can use the same Datasource, or different DataSource... however you like it.

    Running order? I haven't found any official document, from my observation in debug, all liquibase migration runs according to the order you write in application.properties. Those who wants to run migration in one datasource, then go to another datasource, then come back to this datasource and run something else,,, you may want to try this multiple liquibase instance approach.

提交回复
热议问题