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
In this repository64 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- api-backward-compatibilitySkill
- api-design-standardsSkill
- api-versioningSkill
- database-designSkill
- distributed-systemsSkill
- observability-by-defaultSkill
- performance-budgetsSkill
- resilience-patternsSkill
- twelve-factor-appSkill
- codex-cross-reviewSkill
- dispatching-parallel-agentsSkill
- receiving-code-reviewSkill
- requesting-code-reviewSkill
- subagent-driven-developmentSkill
- architecture-awarenessSkill
- intent-to-specSkill
- project-diagnosisSkill
- using-shipworthySkill
- systematic-debuggingSkill
- documentation-as-codeSkill
- accessibilitySkill
- frontend-standardsSkill
- retrospectiveSkill
- writing-skillsSkill
- ci-cd-awarenessSkill
- context-managerSkill
- environment-setupSkill
- feature-flag-disciplineSkill
- finishing-a-development-branchSkill
- guardrail-audit-logSkill
- incident-responseSkill
- mcp-integrationSkill
- migration-strategiesSkill
- production-readinessSkill
- scope-creep-detectionSkill
- session-memorySkill
- slo-sli-definitionSkill
- tech-debt-trackingSkill
- using-git-worktreesSkill
- brainstormingSkill
- decision-frameworksSkill
- design-documentsSkill
- executing-plansSkill
- writing-plansSkill
- code-complexitySkill
- confidence-based-strictnessSkill
- error-handling-patternsSkill
- feedback-driven-adaptationSkill
- quality-gatesSkill
- response-schema-validationSkill
- test-driven-developmentSkill
- verification-before-completionSkill
- adaptive-securitySkill
- bias-detectionSkill
- compliance-awarenessSkill
- container-securitySkill
- dependency-managementSkill
- pii-detectionSkill
- secrets-managementSkill
- The first 60 shown.
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
- Distinctive: line 71
Every migration PR must answer:
- Distinctive: line 79
Never test on an empty database.
- Distinctive: line 81
Test with concurrent reads/writes during the migration.
≈ “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.
Files
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 queriesBackward-Compatible Migration Rules
| Operation | Safe? | How to Do It Safely |
| Add nullable column | Yes | Direct ADD COLUMN |
| Add column with default | Yes (Postgres 11+) | Fast in modern Postgres |
| Rename column | No | Expand-contract |
| Drop column | No | Remove from app code first, drop later |
| Change column type | No | Add new column, migrate data, drop old |
| Add index | Caution | CREATE INDEX CONCURRENTLY |
| Drop table | No | Remove 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:
- What does rollback look like? Can you deploy the previous app version without a reverse migration?
- Is the migration reversible? Adding a column is. Dropping one is not.
- 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
CONCURRENTLYfor 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)
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
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.

