1
votes

I'm using both Java and SQL migrations using Flyway, using the Java API. I have not changed the default locations for the migration folder, that is, I use "db/migration".

But, for the sake of clarity, I would like to have both the SQL and Java migrations in the same folder (Flyway reads the Java migrations from src/main/java/db/migration folder and the SQL ones from src/main/resources/db/migration). I have tried to copy the SQL scripts to the java folder but flyway ignores them.

Is this possible?

1

1 Answers

1
votes

Flyway reads the Java migrations from src/main/java/db/migration

Not exactly. By default, Flyway reads the Java migrations (and SQL migrations) from the classpath. src/main/java contains the source files, not classes.

Your build tool, Gradle / Maven etc, will look for .java source files in src/main/java, compile them and put the classes in some output directory, e.g. build/classes/java/main, target/classes etc. And it is the contents of this output directory that would be on the classpath and therefore visible to Flyway.

In order to get the .sql files from the source directory to the classpath, your build tool needs to be told to copy them.

For example, in Gradle something like this might work (not tested - see the docs for more info):

sourceSets {
    main {
        resources {
            srcDir file('src/main/resources')
            include '**/*.sql'
            exclude '**/*.java'
        }
    }
}