agentleFS
tejastn10tejastn10/workbench/skills/deployment/data-migration/SKILL.md

data-migration

Skill1 starsChanged 2 months agoMITView on GitHub

Migrate a live database safely — additive schema changes first, backfill in batches with no long locks, expand/contract for anything that isn't purely additive, reversible, and decoupled from the code deploy. Postgres / Prisma / Mongo. Use when asked to "add a column / table / index", "write a migration", "change the schema", "backfill X", or "move this data".

9 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 7 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Commit feat(db): <change> or chore(db): ….

    line 45

“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “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

Data migration

Pairs with deployment/code-migration — the schema moves first and additively, the code cutover comes after.

The rule: a migration must be safe to run while the old code is still serving traffic, and the new code must be safe to run against the old schema. Deploy and migrate are separate steps.

Expand / contract for anything not purely additive

ChangeSafe sequence
Add nullable columnone step — add it
Add non-null columnadd nullable → backfill → set default / not-null in a later migration
Rename columnadd new → dual-write in code → backfill → switch reads → drop old (later) — see quality/wide-rename
Change column typeadd new column of new type → backfill → switch → drop
Drop columnstop writing (deploy) → drop (next migration), once nothing reads it
Add indexCREATE INDEX CONCURRENTLY (Postgres) — never a plain CREATE INDEX on a big table, it locks writes
Add NOT NULL / CHECK / FKadd as NOT VALID → VALIDATE CONSTRAINT separately (Postgres)

Backfill

  • In batches with a bounded loop (WHERE id BETWEEN … LIMIT n), commit per batch, sleep between. Never one UPDATE over millions of rows — it locks and bloats the WAL.
  • Idempotent and resumable — safe to re-run after a failure mid-way.
  • A separate script/job, not inside the DDL migration.

Rules

  • Reversible — write the down, or explicitly note "irreversible, forward-fix only" and why.
  • No @Transaction / long transaction across a paginated loop — it pins a pool connection and holds locks (a real flag in the review corpus).
  • Test on a prod-sized copy for timing if the table is large.
  • Mongo — same spirit: additive fields are free; a field rename or type change needs dual-read in code + a batched backfill; MONGO_AUTO_INDEX=false in prod so index builds are deliberate.
  • Commit feat(db): <change> or chore(db): …; keep the migration and any code that depends on it in a sequence the deploy can follow.

Anti-patterns

  • ❌ Add-non-null-with-default in one step on a large table (rewrites every row).
  • ❌ Plain CREATE INDEX on a hot table.
  • ❌ One unbounded UPDATE backfill.
  • ❌ Dropping a column in the same deploy that stops writing it.
  • ❌ No down and no note saying why.

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.

Reviews can't be read right now.

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.