Database Schema Migrations
Evolve a live PostgreSQL schema with versioned Alembic migrations, including data backfills and zero-downtime changes.
4 objectives 6 steps about 130 min
Learn it step by step
Read the lessons in order, try the practice checks, then prove the skill with the knowledge check.
This skill page is a public outline. Its lessons and knowledge check appear here as subject-matter experts approve them.
Learning objectives
- Generate, review and correct Alembic migrations from model changes, and apply or roll them back across environments.
- Write a data migration (backfill) that is idempotent and processes rows in batches.
- Plan a zero-downtime schema change with the expand-migrate-contract pattern, avoiding long-held table locks.
- Run migrations as a controlled deploy step and fail CI when models and migrations drift apart.
Lesson plan
6 steps, about 130 min · 5 of 5 lessons available so far
- Why Schemas Need Version Control Concept · 15 min
- The Alembic Loop: Autogenerate, Review, Apply Worked example · 25 min
- Moving Data, Not Just Columns Worked example · 20 min
- Zero-Downtime Changes with Expand and Contract Concept · 25 min
- Lab: Ship a Column Rename Through CI Without Downtime Lab · 30 min
- Check: Is This Migration Safe to Ship? Knowledge check · 8 questions
Practise it
Rename a heavily used column in your service through three Alembic revisions (expand, batched backfill, contract), keep the API working against every intermediate schema, and add a CI job that fails when models and migrations drift. Exercise the change with production-shaped data and an old app version; demonstrate restore in isolation and distinguish an application rollback from reverting a destructive data migration.
References
Hard prerequisites
Unlocks
On these roadmaps
Progress and evidence for this skill are shared across all of them.