3
votes

I'm trying out flyway and have an understanding problem concerning classpath and JARs.

I have a project with multiple services in multiple maven modules. I want each of the services to maintain its schema with flyway. So each service is a maven module with its own resource directory, where I could put the SQL scripts and which would be part of the JAR. Now, the service can run in embedded mode, where multiple service JARs are present in an end-user application (for example tomcat).

On service initialization I would run flyway migrate with each service's datasource. In case I use java migrations, I could keep the java classes in the same package as the impls and separate by locations, but in case I use SQL migrations, I would have something like this:

src/main/resources/db/migration/V1_1__Populate_table.sql

in each module. Now the question:

  • Can flyway execute sql scripts from jars?
  • If yes, can I specify which jars to execute?
1

1 Answers

7
votes

If the JARs are part of the classpath, the migrations will be picked up.

In your case you should use one Flyway instance per module. This instance is then configured with its own location for SQL migrations, so that only the relevant files are picked up.

Ex: flyway.locations=db/migration/mymodule

There is also nothing stopping from putting the SQL migrations in the same package as the java classes for that module.