agentleFS
Vimalk0703Vimalk0703/shipworthy/skills/operations/zero-downtime-migrations/SKILL.md

zero-downtime-migrations

Skill6 starsChanged 8 months agoMITView on GitHub

Expand-contract pattern, backward-compatible schema changes, feature flags for migrations, rollback plans, and production-like testing for database migrations.

  • Deletes or force-pushes

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Every migration PR must answer:

    line 71
  2. Distinctive:

    Never test on an empty database.

    line 79
  3. Distinctive:

    Test with concurrent reads/writes during the migration.

    line 81

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Zero-Downtime Migrations

Core Principle

During deployment, old code and new code run simultaneously. Every migration must be compatible with both the current and previous version of the application code.

The Expand-Contract Pattern

Phase 1: Expand (add new, keep old)

ALTER TABLE users ADD COLUMN display_name VARCHAR(255);

App code writes to BOTH columns during transition.

Phase 2: Migrate (backfill in batches)

-- Backfill in batches, not one giant UPDATE
UPDATE users SET display_name = name WHERE display_name IS NULL LIMIT 1000;

Phase 3: Contract (remove old, after full rollout + rollback window)

-- Only after ALL app instances use display_name exclusively
ALTER TABLE users DROP COLUMN name;

What Never to Do in a Single Migration

ALTER TABLE users RENAME COLUMN name TO display_name;  -- breaks old code instantly
ALTER TABLE users DROP COLUMN legacy_field;              -- no deprecation
ALTER TABLE users ALTER COLUMN age TYPE text;            -- type change breaks queries

Backward-Compatible Migration Rules

OperationSafe?How to Do It Safely
Add nullable columnYesDirect ADD COLUMN
Add column with defaultYes (Postgres 11+)Fast in modern Postgres
Rename columnNoExpand-contract
Drop columnNoRemove from app code first, drop later
Change column typeNoAdd new column, migrate data, drop old
Add indexCautionCREATE INDEX CONCURRENTLY
Drop tableNoRemove all references first, drop later

Feature Flags for Schema Changes

Gate new schema usage behind feature flags to decouple deploy from release:

if (featureFlags.isEnabled('use-display-name')) {
  return user.display_name;
} else {
  return user.name;  // old column still works
}

Rollback Plan Required

Every migration PR must answer:

  1. What does rollback look like? Can you deploy the previous app version without a reverse migration?
  2. Is the migration reversible? Adding a column is. Dropping one is not.
  3. What is the rollback window? How long before the contract phase makes rollback impossible?

Testing Against Production-Like Data

  • Never test on an empty database. Use a production-sized dataset.
  • Measure lock duration on a copy of production data.
  • Test with concurrent reads/writes during the migration.
  • Backfill scripts must handle millions of rows in batches.

Migration Review Checklist

  • Migration is backward-compatible with currently deployed code
  • No DROP COLUMN, RENAME COLUMN, or type changes in a single step
  • Large tables use CONCURRENTLY for index creation
  • Backfill runs in batches, not a single UPDATE
  • Rollback plan is documented in the migration PR
  • Tested against production-sized data with measured lock time
  • Feature flag gates the new schema usage (if applicable)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.