Spring Boot: Hibernate and Flyway boot order

前端 未结 6 637
一整个雨季
一整个雨季 2020-12-09 03:52

I have created Spring application. Pom xml is attached.

It has a config like this (below) and some db/migration/V1__init.sql for Flyway db migration tool.

It

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-09 04:19

    All SQL migrations will start after Hibernate creates all the tables.

    Spring Boot 2.2.2, Flyway 6.0.8

    To disable boot for Flyway, insert into resources/application.properties:

    spring.flyway.enabled=false
    

    Create separate configuration for Flyway to make it load when Hibernate is ready:

    @Configuration
    public class FlywayConfiguration {
    
        @Autowired
        public FlywayConfiguration(DataSource dataSource) {
            Flyway.configure().baselineOnMigrate(true).dataSource(dataSource).load().migrate();
        }
    }
    

    Start your migration scripts from version 2:

    resources/db.migration/V2__fill-tables.sql
    

    V1 is used as a baseline, V1 file will be ignored.

提交回复
热议问题