Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flyway migration with single schema and multiple projects

Tags:

flyway

I have a question related to Flyway DB Migrations. How to generally manage multiple projects (microservices) dealing with the same DB schema. The Flyway migration scripts in each of the project does not allow to start if it is modified by the other project. Do they have any documentation or best practices on the same?

like image 616
user3808122 Avatar asked Mar 22 '17 13:03

user3808122


People also ask

Does Flyway support multiple schemas?

To create multiple identical schemas you have to invoke Flyway once for each schema, with the flyway. schemas property set the to correct value. Flyway will then set the correct schema as the default one, letting you run your migration scripts unchanged (as long as you don't prefix the object names).

Does Flyway automatically create schema?

flyway has gained the ability to automatically create (and drop) schemas. in addition to these three new features, this releases packs numerous bug fixes and small improvements .

What is repeatable migration in Flyway?

Repeatable migrations are very useful for managing database objects whose definition can then simply be maintained in a single file in version control. Instead of being run just once, they are (re-)applied every time their checksum changes. They are typically used for. (Re-)creating views/procedures/functions/packages/ ...


4 Answers

We are in the process of doing this. We have one central project that manages the schema creation/management, and other projects handle their own function creations all via their own flyway versioning. This is done by changing the name of the table that those other projects check their schema version against, and setting baseline on migrate to true. We are using spring/flyway-db configuration so this was simply adding the following to application.properties for each project in addition to the first.

flyway.baselineOnMigrate=true
flyway.table=schema_version_*<some_other_identifier>*

I know your question did not specify a spring configuration explicitly, but I believe this can be configured not matter how you are using flyway. I wanted to post an answer as when I was googling the question myself, your SO question was the top result, and I figured my answer might help someone down the track.

like image 70
Jags Avatar answered Jan 03 '23 23:01

Jags


For what it is worth, this is what we did. Since the schema was shared by multiple projects we had the schema managed by a single project whose task was to maintain said schema. Centralizing schema creation and maintenance had other benefits in that we had single locus of change. We needn't scan several projects for changes.

I honestly think this is the best solution. I don't believe flyway has inter-project schema dependency management.

like image 32
sagneta Avatar answered Jan 04 '23 00:01

sagneta


I have faced same issue, because I was working with 2-3 micro services, So what I did is as below example, running in following sequence

micro-service-1 ( which required migration )
micro-service-2
micro-service-3 ( which required migration )

So I created flyway migration v1__description.sql in micro-service-1 and then in micro-service-3 I created v1_2__description.sql because it is at 3rd in sequence of running projects, this is my release version 1, which are having 2 migration with version 1 and 1.2

micro-service-1 ( V1_description.sql )
micro-service-2 // if in future it reuires migration then we can use, V<<currentVersion>>_1__description.sql
micro-service-3 ( V1_2_description.sql )
like image 34
Onkar Saravade Avatar answered Jan 04 '23 00:01

Onkar Saravade


if any one using the Play frame work this problem can be tackle with independent flyway history tables for each microservice mean every mircoservice has its own flyway history table with name according to service. this ll create flyway table for each service add these properties in conf file for changing the flyway table name.

db.default.migration.table=microservice1    for 1 mircoservice
db.default.migration.table=microservice2    for 2 mircoservice

add this property in every microservice conf file this is only for play frame work

like image 25
Basharat Ali Avatar answered Jan 04 '23 01:01

Basharat Ali