migration-writer
Skill1 starsChanged 3 months agoMITView on GitHub
Write a safe, reversible, zero-downtime database migration using expand-contract — add the new shape, backfill in batches, switch reads/writes, then drop the old — so every deploy stays compatible with the running app version. Use when adding or changing schema on a live system, renaming/dropping a column, adding NOT NULL or a foreign key on a large table, or when a migration risks locks, table rewrites, or an unrevertable step.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- Archive228/loopkittheir own version, first seen Jun 29, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- Archive228/loopkit★ 756same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository134 other files it gives its agents.
- agents.mdAGENTS.md
- accessibility-regression-auditorSkill
- adr-writerSkill
- agent-memory-designerSkill
- agent-trajectory-evaluatorSkill
- alerting-rules-tunerSkill
- analysis-memo-writerSkill
- api-deprecation-plannerSkill
- api-error-contract-designerSkill
- architecture-diagram-generatorSkill
- auth-flow-reviewerSkill
- background-job-reliability-auditorSkill
- branch-rebaserSkill
- brand-voice-profilerSkill
- bundle-analyzerSkill
- cache-policy-designerSkill
- canary-release-plannerSkill
- changelog-from-prsSkill
- chart-chooserSkill
- chunking-strategy-optimizerSkill
- circular-dependency-breakerSkill
- claude-settings-auditorSkill
- code-example-verifierSkill
- cold-email-deliverability-auditorSkill
- cold-start-optimizerSkill
- commit-splitterSkill
- competitor-teardownSkill
- component-spec-writerSkill
- connection-pool-tunerSkill
- content-repurposerSkill
- contract-test-designerSkill
- conventional-commitsSkill
- cors-configuratorSkill
- coverage-gap-finderSkill
- crm-export-auditorSkill
- dashboard-designerSkill
- data-retention-auditorSkill
- dataset-first-lookSkill
- dead-code-finderSkill
- deadlock-diagnoserSkill
- dependency-auditSkill
- dependency-upgrade-plannerSkill
- design-brief-writerSkill
- design-critique-checklistSkill
- design-token-extractorSkill
- devcontainer-designerSkill
- distributed-tracing-instrumenterSkill
- dockerfile-optimizerSkill
- email-sequence-drafterSkill
- embedding-index-tunerSkill
- embedding-set-inspectorSkill
- extract-moduleSkill
- feature-flag-retirerSkill
- finetune-dataset-builderSkill
- flaky-test-diagnoserSkill
- flamegraph-analyzerSkill
- git-blame-investigatorSkill
- github-actions-optimizerSkill
- graphql-schema-designerSkill
- graphrag-scaffolderSkill
- The first 60 shown.
The file
Files
Most schema migrations break production not because the SQL is wrong but because they assume the database and the app flip over in one atomic instant. During a rolling deploy, old and new code run at the same time against one schema — so a migration that the new code needs will crash the old code, and a rollback that the old code needs is gone the moment you DROP. This skill writes migrations the expand-contract way: each step is independently deployable against the version before and after it, every change has a real down, and no step takes a lock that blocks writes on a hot table.
When to use this skill
- Adding, renaming, dropping, or retyping a column on a table that a live app reads/writes.
- Adding
NOT NULL, aCHECK, a foreign key, or a unique constraint to a table with existing rows. - Creating an index on a large/busy table, or backfilling a new column across millions of rows.
- Splitting/merging tables, moving a column, or any change where old and new app code must coexist during the deploy.
Instructions
- Decide the expand-contract phases first, before writing SQL. A column rename
a → bis not one migration; it is: (1) addbnullable, (2) dual-writeaandbin app code, (3) backfillbfroma, (4) switch reads tob, (5) stop writinga, (6) dropa. Each phase ships and is safe to roll back to the phase before it. Name the phases explicitly in the output, mapped to app deploys. - Make additive changes nullable / without a default rewrite.
ADD COLUMN ... NULLis instant. Adding a column with a non-constant default (or, on old engines, any default) rewrites the table under a lock — split it into add-nullable, then backfill, then set default for future rows. - Add
NOT NULLandCHECKwithout a blocking scan. On Postgres:ADD CONSTRAINT ... CHECK (...) NOT VALID, thenVALIDATE CONSTRAINT(takes only aSHARE UPDATE EXCLUSIVElock, doesn't block writes). ForNOT NULL, add the validatedCHECK (col IS NOT NULL)first, then promote — neverSET NOT NULLcold on a big table, which full-scans under anACCESS EXCLUSIVElock. - Build indexes and FKs concurrently / unvalidated.
CREATE INDEX CONCURRENTLY(andDROP INDEX CONCURRENTLY) so writes keep flowing; add foreign keys asNOT VALIDthenVALIDATE CONSTRAINTin a second step. Concurrent index builds run outside a transaction — keep them in their own migration with no other statements. - Backfill in bounded batches, never one transaction. Update in chunks (e.g.
WHERE id BETWEEN ...orLIMIT nloops) committing each batch, with a short sleep between batches to spare replication and locks. Keep the backfill in a separate migration/job from the schema DDL so a slow backfill can't hold a DDL lock and a failed batch doesn't roll back the whole table. - Write a real
downfor everyup. The down must actually reverse the change (drop the added column/index/constraint), or, where reversal loses data (a dropped column, a narrowed type), say so loudly and add an export/backup step to the up rather than pretending it's reversible. - State the deploy ordering contract. For each migration, note which app version it requires and which it must remain compatible with: backward-compatible (expand) migrations run before the code that needs them; destructive (contract) migrations run after all code that used the old shape is fully rolled out and confirmed.
[!WARNING] A single-transaction backfill (
UPDATE big_table SET ...with no batching) holds row locks on every touched row until commit, bloats WAL, can deadlock with live traffic, and on failure rolls back hours of work. Always batch and commit; treat any unboundedUPDATE/DELETEon a large table as a production incident waiting to happen.
[!WARNING] Type changes that rewrite the table (
ALTER COLUMN ... TYPEbetween incompatible types, e.g.int → biginton older Postgres) take anACCESS EXCLUSIVElock and block all reads and writes for the duration. Prefer expand-contract: add a new column of the target type, backfill, switch over, drop the old — never an in-place rewrite on a hot table.
[!NOTE] Don't take
ACCESS EXCLUSIVEDDL withlock_timeout = 0. Set a shortlock_timeout(e.g.5s) so a migration that can't grab its lock fails fast and retries, instead of queueing behind a long query and stalling every write that piles up behind it.
Output
For the requested change, produce:
- The
upanddownmigration — split into separate files per expand-contract phase, withCONCURRENTLY/NOT VALID/VALIDATEused where they avoid blocking locks. - The backfill + rollout sequence — the ordered phases (add → dual-write → backfill → switch reads → stop old writes → drop), each tagged with the app deploy it pairs with, and the batched backfill loop as a separate step.
- Locking & risk notes — for each statement: the lock it takes, whether it blocks reads/writes, whether it rewrites the table, and whether the
downis lossless — with destructive/irreversible steps called out explicitly.
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.

