Skip to content
Advertisement

How can i use Flyway migration with single schema and multiple projects

How to manage multiple projects 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.

For example:

I have a spring boot Project X with a FlywayInitializer class.

And i have a submodule Project Y with also his own FlywayInitializer class

Project Structure:

How can i use the for both Project X and Y the same schemaname “schema1” with Flyway ?


EDIT: Thanks @jesper_bk that helped me. Its exactly what i wanted, that the two projects have completely “independent lives” in the same schema. But now i have the following problem:

The first executed project X create tables correcty, but if Project Y is started i get the error Found non-empty schema without metadata table. So i have to set BaselineOnMigrate to true. But if i set BaselineOnMigrate to true the Project Y skip the sql file V1.0_create_tableY.sql and starts with V1.1_update_tableY.sql. How can i reach, that the first sql script V1.0_create_tableY.sql is also executed for Project Y?

Advertisement

Answer

If you can live with two projects having completely “independent lives” in the same schema, you could use separate version tables for the two, i.e.:

If you want them to use the same versioning scheme, you are probably better served with putting all SQL scripts in separate third project, or – even more complicated – have a third project that automatically gathers and enumerates the SQL scripts from the main project.


Concerning your second question, baselineVersionAsString should be < 1 (e.g. 0). If the baseline version is 1, it will determine that your first script with version 1.0 matches the baseline, and should already have been executed.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement