Friday, January 6, 2023

Re: Data migrations ran multiple times during deploy

tl;dr it's not safe to run multiple migrate simultaneously

On January 5, 2023 7:47:54 PM CST, Harris Lapiroff <> wrote:
Hi, all! Curious about how folks do data migrations as we ran into an issue recently:

Our production deployment consists of three containers running the application. When each container comes up it runs a series of startup tasks include `./ migrate`. Usually it's fine to run this whenever because it's idempotent and Postgres should reject simultaneous schema changes.

So I was surprised recently when we performed a deploy that included a data migration that created some objects and it created the objects multiple times. I'm assuming what happened is that the containers each kicked off a migration command simultaneously (thus all three containers saw that the migration hadn't been run yet) and Postgres didn't block any of the transactions as conflicting.

How do you all avoid this?


No comments:

Post a Comment