Setting up multiple database with Flyway

13,358

I suspect you might be using Spring Boot 2.x here? If so, flyway.locations is no longer valid and will be ignored.

Flyway will then just use the default location (db/migration), which will find only the V1.1__Insert_Records.sql script but not the V1__Create_table.sql script.

With Spring Boot 2.x, flyway.locations must be prefixed with spring.:

spring.flyway.locations=db/migration,db/specific/h2

By the way, if you use the {vendor} placeholder in the location, Spring Boot will work out the directory from the lowercase of the database driver id (h2, mysql, oracle, etc), which is nice:

spring.flyway.locations=db/migration,db/specific/{vendor}
Share:
13,358
Meena Chaudhary
Author by

Meena Chaudhary

Updated on June 11, 2022

Comments

  • Meena Chaudhary
    Meena Chaudhary almost 2 years

    I am trying to setup two different database with Flyway 5.0.7, MySQL for development and H2 for testing. I have configured both databases in respective files.

    For Development, src/main/resource/application.properties

    spring.datasource.url=jdbc:mysql://localhost:3306/moment
    spring.datasource.username=root
    spring.datasource.password=root
    
    flyway.locations=db/migration,db/specific/mysql
    

    For Testing, src/test/resource/application.properties

    spring.datasource.driver-class-name=org.h2.Driver
    spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
    spring.datasource.username=sa
    spring.datasource.password=sa
    
    flyway.locations=db/migration,db/specific/h2
    

    Below is the folder structure for Flyway migration files

    Flyway migration file structure

    In this case Flyway is not able to find migration files under specific folder and throws error when applying V1.1__Insert_Records.sql for table not found.

    If I move the specific folder inside db/migration, I am getting error for duplicate files of same version.

    Any suggestions how should I configure migration files for multiple databases to work with Flyway?

  • xtra
    xtra over 4 years
    I had to be specific about the location by prefixing with classpath: spring.flyway.locations=classpath:/db/migration,classpath:/d‌​b/specific/h2