Wrap startup migrations in a Postgres advisory lock #16
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem. Migrations are embedded and applied automatically on startup.
The moment a second API replica exists (or a restart races a slow migration),
two processes run the migration path concurrently — partial DDL, duplicate
inserts, or a wedged schema, on the database that is the source of truth for
the entire firewall estate.
Proposal.
pg_advisory_lockaround the migrate step (one line with mostmigration libraries); replicas that don't win the lock wait and proceed once
the schema is current. Cheap now, painful to retrofit after an incident.