Found more than one migration with version XXXX

rsksmilesrsksmiles Posts: 3 New member
edited November 14, 2024 10:28AM in Flyway (General Discussion)
I have an issue whereby 2 developers in a team are working in the same GIT branch and making database modifications.

They both create a script say V2_1_25__bla_bla1 and V2_1_25__bla_bla2
These changes are committed to GIT.

When the refresh their code they then see the 2 script files but when they try to run flyway to update the database the execution fails due to the duplicate version numbers: "Found more than one migration with version 2.1.25"

What is the best way to handle this?

Thanks for your help in this
Tagged:

Best Answers

  • AlistairWAlistairW Posts: 36 Bronze 2
    The conventional approach is to check before committing - Flyway uses the version numbers to order your migrations and it may be important which V2 is applied first.
    An alternative is to embed a timestamp in the version number which makes it very unlikely that you'll get a conflict. You can develop your own process for this or else there is a new verb in preview that can create the empty migration for you - https://documentation.red-gate.com/fd/command-line-add-254155068.html
    So you'd want something like this to create the file: 
    flyway add -add.description=new_feature -add.addTimestamp=true

  • AlistairWAlistairW Posts: 36 Bronze 2
    You run into the limitations of a point tool - the situation you describe needs some way of coordinating everyone and that is non-trivial. Flyway aims to solve the problem of being able to change your DB in a controlled manner and recreate it's current state should you need to do so. Coordinating development work is a related problem but will involve other tools and practices to solve (Redgate has some but they aren't free)
    On your specific question though, dev1 would need to clean their development DB and re-apply all the migrations which would correct the ordering to include dev2's changes. 

Answers

  • rsksmilesrsksmiles Posts: 3 New member
    edited November 14, 2024 11:03AM
    Thanks AlistairW I will try out the timestamp approach. 

    This resolves the issue of the version number but what happens if dev 1 has run their change on his db and dev 2 has a change with an earlier timestamp? flyway won't consider the earlier version when dev 1 receives that script.
    Is there a way to force flyway to execute unexecuted scripts? I can see that can lead to issues where a certain script should be run after another and not before.... comes down to communicating clearly between devs which is not always easy in multi timezone teams ... aaagggh!

    Does that make sense?
  • rsksmilesrsksmiles Posts: 3 New member
    Thanks again for your time with this - it is greatly appreciated.

    Whilst it would be nice to have an out of the box solution, I can work with the "lets talk" solution within the team.
  • If earlier pending scripts are pulled into your project that need to be applied then you can set flyway.outOfOrder=true . This is okay in a dev context, but less of a good idea for production. 
    David Atkinson
    Product Manager
    Redgate Software

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file