How to manage flyway migration across multiple apps sharing same database.
How should we manage flyway migration scripts
You can have a module containing all migration scripts, which can be added as a dependency by all services (A, B and C in your example). Once you have that in place, only one of the services should run the migrations e.g, service A and the other services (B and C) should just validate the schema. As an advantage, if you are running integration tests on your services, they can run flyway independently at test time or on your CI/CD pipeline to execute the test. Even for local development, Flyway can be activated.
Unfortunately, this introduces a slight dependency on the deployment order of your services, they can still be deployed in any order, but till the service in charge of the migration's executions does its job, the other will be unhealthy. If you use some kind of Blue/Green deployment style, silos or similar, this should not be a problem, but just something to consider.
If you decided to try something like that, you just need to overwrite the Flyway migration phase and leave the migration method empty while the validation still operative. I think you need to look at FlywayMigrationStrategy
, but I haven't done it in some time, check yourself first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With