Skip to content

CICD-320 · Expand-contract migration pattern ​

Encyclopedia · Database delivery and migration · All snippets

Previous · CICD-319 · Next · CICD-321

1. Where it fits ​

  • Placement migrations/expand.sql.
  • Prerequisites disposable database, migration tools and a scoped database role.
  • Platforms local-lab.

2. Copy the snippet ​

sql
ALTER TABLE accounts ADD COLUMN IF NOT EXISTS display_name text;

3. How it works ​

The expand migration adds a field old clients can ignore. A verified backfill and reader cutover must happen before removing the old schema path.

Old and new application revisions overlap during expansion.

flowchart TD
  N1["Add nullable column"]
  N2["Old clients continue"]
  N1 --> N2
  N3["New readers and writers"]
  N1 --> N3
  N4["Backfill and verify"]
  N3 --> N4
  N5["Retire old clients"]
  N2 --> N5
  N6["Contract only after retirement"]
  N4 --> N6
  N5 --> N6

4. Verify the result ​

Deploy dual write and a resumable backfill, verify null counts and remove the old readers before the separately reviewed contract migration.

Validation untested. Status definitions.