Flyway migration with multiple instances pointing at the same schema

Viewed 520

We are not using Flyway yet, but I am researching it now in the hopes of implementing it in the next few months.

We would like to have the application run the migration check at startup. However we have two different apps working together in the same database, and multiple instances of each. my hope is that the first one through the gate will add a Pending record to the history table and the others will not also try to upgrade seeing that.

Is that a realistic expectation?
Can we rely on that mechanism? How do others handle this? Thanks.

2 Answers

It depends on the database. Those that support explicitly taking and releasing table locks via the JDBC driver should lock the history table at the start of a migration, thereby blocking any other Flyway instances from proceeding, and release the lock at the end. There are a couple of databases we know of (CockroachDB is one) which don't allow this, and for them a Pending row in the database is inserted and then deleted.

The flyway download page claims "Safe for multiple nodes in parallel" as one of their features. I've read they use locks to achieve this.

Related