Video in progress

Staff 🌿 Git

Two developers used the same Flyway version on parallel branches. How do you prevent such collisions at the system level?

feature/loyalty:  db/migration/V42__add_loyalty_points.sql
feature/invoices: db/migration/V42__create_invoice_table.sql

Sequential numeric versions will inevitably collide in parallel work. The solution is to use a timestamp as the version, run flyway validate in CI together with main, and use a merge queue to guarantee migrations land on main one after another.

📖 Answer

Git shows no conflict here, because the file names are different. Both PRs are green separately, and on main the app does not start, with Flyway saying Found more than one migration with version 42. A worse case: the first one has gone to prod, and the second must be renumbered, but it has already been applied on the staging DB.

The protections I put in place:

  • Version format. V2026_11_03_1412__add_loyalty_points.sql is time based, so the chance of a collision is tiny. But now the order can be violated: a migration that merged later stays at a lower version. Flyway treats this as an error by default. Turn on outOfOrder=true only if you are sure the migrations are independent of each other;
  • A CI check. Apply all migrations to an empty DB (with Testcontainers) with the PR branch merged with main. This catches the collision before the merge;
  • A merge queue. The "compatible with main" check runs for each PR against the very latest state;
  • An owner. CODEOWNERS for db/migration/, so at least one person looks at migrations from an ordering point of view.

One more rule: never edit a migration that has been applied. The Flyway checksum will not match and the next deploy fails. If there is a mistake, write a new migration.