Application-Module Aware Flyway Migrations
As of Spring Modulith 2.0, we support the execution of module-specific Flyway migrations. Application modules are encouraged to define migrations for their own persistent data only, which means that these migrations have to be executed in the order of the module dependency tree.
Assume a default Flyway setup with migrations located in classpath:db/migration, two application modules first and second (with second depending on first), and an activated spring.modulith.runtime.flyway-enabled configuration property.
With that in place we will customize the Flyway setup as follows:
The root migration folder will be changed to db/migration/__root. For that, the default version tracking table will be used.
Additional migrations for db/migration/$moduleIdentifier will be registered with a tracking table of flyway_schema_history_$moduleIdentifier. These migrations are also set up to a baseline version of 0 and set up to baseline on migrate.
Migration locations ending in a wildcard will not be customized.
Note, that he version numbers used in migration scripts are now effectively scoped to the application module and should not use global ordering.
By selecting which folder to place the migration files in, you can differentiate migrations always to be run from ones that will only get executed for the corresponding module. The application module test integration will only execute the default migration and the ones for modules included in the test run.
We've tweaked the way #SpringModulith's #Flyway support customizes the application-module-aware migrations. Now fully isolated, migration history per module. Please give it a spin before our GA release next week! 🍃📦
docs.spring.io/spring-modul...