Search code examples
spring-bootflywayspring-boot-test

How to set flyway path configuration for test using filesystem in configuration file?


I have setup flyway task for Local using a configuration file and wiring up to my task like

tasks.create<FlywayMigrateTask>("migrateLocal") {
    configFiles = arrayOf("config/flyway/flyway.conf")
}

This task runs okay and the scripts are executed well, However when I try running integration tests with an application-TEST.yaml file where I define the configuration paths, I get the error below

Flyway failed to initialize: none of the following migration scripts locations could be found:

    - classpath:db/migration

The thing is I dont want to redefine the same configurations in the test folder, I want to reference them from file system using my application-TEST.yaml in the resources folder of test package like this

flyway:
    schemas: public
    locations: filesystem:doc/flyway/migrations,filesystem:config/flyway/archive,filesystem:config/flyway/post_migrations

If I try that, I get the same Flyway failed to initialize when I ran a single test, infact context fails to load

java.lang.IllegalStateException: Failed to load ApplicationContext

Any help would be highly appreciated


Solution

  • For anyone trying to set up something similar, You have to annotate the integration test with

    @ActiveProfiles("TEST")
    

    "TEST" is the configuration profile ("application-TEST.yaml").

    Everything worked okay after that.