I have two Spring profiles dev
and test
configured for development and test environment. And in each environment I am using different databases viz h2
in dev and postgresql
in testing. Following are my properties files for each profile where {vendor}
is resolved by spring boot to h2
and postgresql
repectively as per datasource configured.
application-dev.properties
spring.flyway.locations=classpath:db/migration/{vendor}
application-test.properties
#Data source
spring.datasource.url=jdbc:postgresql://localhost:5432/test
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
#Flyway
spring.flyway.check-location=false
spring.flyway.locations=classpath:/db/migration/test/{vendor}
Flyway migration files for dev
profile are under test/resources
and for test
profile under main/resources
This is working fine when I run my application with test
profile where it picks migration files only under main/resources
. However, When I run my unit test using dev
profile. I expect it to pick files only under src/test/resources/db/migration/h2
. But Flyway is picking up migration files from main/resources
and test/resources
both leading to error
org.flywaydb.core.api.FlywayException: Found more than one migration with version 1
I don't understand this behavior. Any inputs on how to fix this?