FlywayConfig.java

package com.tradecloud.repository.multitenant;

import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.output.RepairResult;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

import javax.sql.DataSource;

@Configuration
public class FlywayConfig {

    /**
     * Runs database migrations at application startup.
     */
    @Bean(initMethod = "migrate")
    @DependsOn("XADataSourceAuthentication")
    public Flyway authenticationFlyway(DataSource dataSource) {

        Flyway flyway = Flyway.configure()
                .outOfOrder(true)
                .dataSource(dataSource)
                .baselineOnMigrate(true)
                .locations("classpath:db/mapping")
                .load();
        RepairResult repair = flyway.repair();
        if (repair != null) {
            MultiTenantConnectionProviderImpl.logRepairsDone(repair);
        }
        return flyway;
    }
}