2
votes

In my spring-boot project I'm using out-of-the-box integration for Flyway (org.flywaydb.flyway-core) and have some migration scripts which are executed on startup and managed via default flyway_schema_history-table.

The project also uses a module bringing its own flyway migration scripts, which are migrated programmatically and keeping track of migrations in an other moduleX_schema_history-table.

As the migrations of the main-project needs to work on some of the tables created via the modules migration, the module-migration needs to happen before the flyway-plugin migrates the main-projects scripts.

How can I achieve executing modules migration programmatically and before the main-apllications fly-integration kicks in? How and when is the flyway-plugin migration triggered?

//EDIT: I tried to execute code before FlywayAutoConfiguration via a @Configuration class annotated with

@AutoConfigureBefore({FlywayAutoConfiguration.class})
@AutoConfigureAfter({DataSourceAutoConfiguration.class})

but unfortunatly the class is still instanciated after FlywayAutoConfiguration.

//EDIT: I asked the related (more general) question how to order AutoConfiguration from modules, too How to use @AutoConfigureOrder in a spring boot configuration class from a module - Stack Overflow

1
what do you mean by spring boot flyway plugin? Are you referring to the maven plugin? - Abhinaba Chakraborty
no I mean the out-of-the-box integration for Flyway (sorry for beeing unclear about that) - kai-dj

1 Answers

2
votes

Flyway migration will kick-in during startup if you configured it correctly in your application yaml/properies file.

In order to start another flyway migration before the main app migration you can use flyway command line or create an separate custom_pom.xml project file for another module and trigger it via mvn plugin from command line: mvn flyway:migrate before executing the main app.