Video in progress
20 teams work on one platform and each writes its own migrations. What do you do so a dangerous migration doesn't reach prod?
I put the rules into the pipeline, not into people's memory: a migration linter in CI (squawk, for example), an automatic trial on a prod copy, lock and duration checks, a mandatory lock_timeout, and a review by the DB owner for dangerous changes. For the rest, documentation and ready-made templates.
📖 Answer
On one big team, an experienced DBA can read every PR. With 20 teams that becomes a bottleneck, and something gets through anyway. So the protection is layered:
- Static checks in CI. An SQL linter finds dangerous patterns in the migration files:
CREATE INDEXwithoutCONCURRENTLY;- an FK or CHECK without
NOT VALID; - changing a column type (rewrites the table);
- adding
NOT NULLto a big table; - DDL without
lock_timeoutset.
An error blocks the PR; an exception only with a comment (-- squawk-ignore ... and a reason).
-
Dynamic checks. The pipeline runs the migration in an environment with the prod schema and anonymized data close to prod volume, and measures the duration. If it exceeds 5 seconds, there's a warning and a review is required.
-
Runtime protection.
ALTER ROLE migrator SET lock_timeout = '3s'for the migration role: even if the linter lets something through, the migration won't clog prod, it will only fail itself. -
People. Through CODEOWNERS, one review from the platform team for
db/migration/**, mandatory only in cases the linter warned about. An internal guide: "zero-downtime migration recipes", each with ready SQL. -
Learning. After every migration-related incident, a new rule is added to the linter.
After this system, migration-related incidents dropped sharply for us, and most importantly, review stopped being a burden for the platform team.
Sign up to mark studied questions and save your progress.