Schema Migration

Procedure — schema migration

ai-driven-dev 8106914 855 B Updated

File contents

Procedure — schema migration

Two releases, never one. The rule exists because we took production down for 11 minutes in November doing it in one.

Release N — additive only

  1. Add the column, nullable, with no default. A default on a large table rewrites it.
  2. Backfill in batches, out of band. Never in the migration itself.
  3. Write to both old and new column. Read from the old one.

Release N+1 — once the backfill is verified

  1. Read from the new column. Keep writing to both.
  2. Verify for one full week, with the metric that counts disagreements between the two.

Release N+2

  1. Stop writing to the old column.
  2. Drop it.

The check that must pass before each step

SELECT count(*) FROM t WHERE new IS NULL AND old IS NOT NULL returns 0.

ai-driven-dev/laivel-up/tree/main/profiles/leodagan/repo-context/.claude/skills/schema-migration commit 8106914ff2

Frequently asked questions

npx skillmds@latest add ai-driven-dev/schema-migration