Search code examples
scalaslickflyway

Flyway not finding my migrations file in sbt


I'm trying to apply the migrations to stand up an H2 database in test, my folder structure is:

src
- test
-- resources
--- db
---- migration
----- V1_0__init_tables.sql

I have my configuration set up to point at classpath:db/migration via

        Flyway
          .configure()
          .locations(migrateLocations)
          .dataSource(url, user, password)
          .load()
          .migrate() 

When I run my tests I get the following output

2018-11-29 16:14:14,351 DEBUG [ScalaTest-run] slf4j.Slf4jLog (Slf4jLog.java:45) - Scanning for classpath resources at 'classpath:db/migration' ...
2018-11-29 16:14:14,351 DEBUG [ScalaTest-run] slf4j.Slf4jLog (Slf4jLog.java:45) - Determining location urls for classpath:db/migration using ClassLoader sun.misc.Launcher$AppClassLoader@18b4aac2 ...
2018-11-29 16:14:14,420 WARN  [ScalaTest-run] slf4j.Slf4jLog (Slf4jLog.java:53) - Unable to resolve location classpath:db/migration
2018-11-29 16:14:14,421 DEBUG [ScalaTest-run] slf4j.Slf4jLog (Slf4jLog.java:45) - Scanning for classes at classpath:db/migration

which leaves me confused as to why Flyway isn't able to find my file. As far as I can tell I've done everything according to what the docs recommend. My test eventually fails because my table was never migrated and thus can't be found by Slick.

It's possible there is an error in my migration file, but I would assume Flyway would have some sort of logging for this? I don't see anything like that.


Solution

  • Did you place your migration files intentionally under src/test/resources? Anyway, I don't think Flyway will find them there, as your classpath:db/migration will most likely refer to src/main/resources, and not to test resources. Just try and place your migration files under main resources.