How to handle merging of branches that are not in a sequence in combination with Flyway

635 views Asked by At

I just encountered the following situtation:

The test-server is currently running Flyway, with version 1 (V1). The test-server is automatically updated (including Flyway scripts) whenever anything is pushed on the develop branch.

A developer decides to start working on a new feature on branch feature/123. This developer creates a database script (Flyway compatible) called V2__cool_feature.sql. In the meantime, another developer also starts working on a feature branch called feature/456. This developer is also in need of an update script, and names it V3__another_cool_feature.sql, because the developer knows that V2 is already used on another branch. This feature/456 branch is finished and is merged, and so the current scripts on the develop branch are V1 & V3. This works well and the V3 script is executed, leaving Flyway its schema_version on version 3.

The other feature branch feature/123 is also merged, which means that the develop branch contains the scripts V1, V2 & V3.

Now this is were I'm having trouble with Flyway:

The build, including Flyway, is executed and it leaves the following message:

[INFO] Database: jdbc:mysql://example.com:3306/my_schema (MySQL 5.5)
[INFO] Successfully validated 2 migrations (execution time 00:00.019s)
[INFO] Current version of schema `my_schema`: 3
[INFO] Schema `my_schema` is up to date. No migration necessary.

What I want to happen is that the V2 script is executed, and I'm not sure how to do so.

I hope I explained my problem well, if not, please leave a comment.

2

There are 2 answers

3
Jelle den Burger On

Ugh, I'm not a smart guy. Putting a bit more effort into my Googling skills lands me upon the Flyway documentation, describing exactly my problem:

Option: outOfOrder

Required: NO

Default: false

Description: Allows migrations to be run "out of order". If you already have versions 1 and 3 applied, and now a version 2 is found, it will be applied too instead of being ignored. (Even the same versioning as in my question is used >.< )

0
Chamin Wickramarathna On

You can use the flyway.outOfOrder configuration parameter to tell Flyway to run missing migration scripts instead of skipping them.

This property is set to false by default. You would have to set it to true.

In a Spring Boot application, you can set

spring.flyway.out-of-order=true

In the command line, you can pass a JVM parameter

-Dflyway.outOfOrder=true

For more details refer: https://www.baeldung.com/flyway-migrations