Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manage flyway migration across multiple apps sharing same database

How to manage flyway migration across multiple apps sharing same database.

  1. Service-A based on Spring Boot, points to Database-A
  2. Service-B based on Spring Boot, points to Database-A
  3. Service-C based on Spring Boot, points to Database-A

How should we manage flyway migration scripts

  1. Should we have a separate repository for managing the database scripts
  2. Since each of the services are launched as docker containers and we don't want the migration to be triggered on each of the container
  3. What would be the preferred way to manage the flyway migration scripts, so that it allows us to rollback or promote changes in a CI/CD environment
like image 755
Rpj Avatar asked Oct 15 '25 23:10

Rpj


1 Answers

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.

like image 174
fjavierm Avatar answered Oct 18 '25 16:10

fjavierm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!