agentleFS
qyndexqyndex/claude-init/.claude/skills/db-migration/SKILL.md

db-migration

Skill2 starsChanged 5 months agoMITView on GitHub

Expand/contract pattern for zero-downtime database schema changes. Replaces the (wrong) \"forward-only by default\" rule. The four-phase pattern: expand → backfill → cutover → contract.

24 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use api-endpoint, write-tests and 4 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • tadoEngSkill

    api-endpoint

    Add or change a backend API endpoint on this product, keeping Pydantic as the single contract authority and regenerating the TypeScript client. Use when asked to add an endpoint, expose data to the frontend, change a request or response shape, or wire a new backend capability into a page.

    Also in 4 projects that use this

  • SentrySkill

    write-tests

    Write tests following project conventions. Use when adding new tests or modifying existing ones.

    Also in 3 projects that use this

  • Microsoft AzureSkill

    git-workflow

    Squad branching model: dev-first workflow with insiders preview channel

    Also in 3 projects that use this

  • Microsoft AzureSkill

    design

    Design rules and conventions for the API Center Portal. Use when editing detail pages, card components, badges, layout, navigation, sidebars, or headers. Covers badge styling, metadata placement, page navigation patterns, and layout alignment.

    Also in 3 projects that use this

  • VercelSkill

    agent-browser

    Automates browser interactions for web testing, form filling, screenshots, and data extraction. Use when the user needs to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, or extract information from web pages.

    Also in 3 projects that use this

  • MicrosoftSkill

    release

    Use ONLY when the user explicitly asks to cut/publish a Huabu desktop release or tag a version. Performs an outward action — bumps the version in apps/desktop/package.json, commits + annotated-tags vX.Y.Z, and pushes the branch + tag. That tag push auto-builds the macOS/Windows installers and publishes a GitHub Release. Provides `status`, `bump`, `tag-push`, and a one-command `run` (bump → tag-push).

    Also in 3 projects that use this

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 21 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:

    Long-running migrations: use lock_timeout and statement_timeout to avoid blocking pile-ups.

    line 74

“Common” is measured: kept by at least 6 in 10 of the 21 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

DB Migration — Expand / Contract

Zero-downtime schema changes require the four-phase pattern. A single "forward-only migration" deploy is wrong for any non-trivial change at scale.

The four phases

Phase A — EXPAND
  - Add new schema element (column, table, index) — additive only
  - Old code continues to work (it doesn't see the new element)
  - Deploy and verify no errors

Phase B — DUAL-WRITE / BACKFILL
  - New code writes to BOTH old and new (dual-write)
  - Backfill historical data into the new element (batched, off-peak)
  - Old code still reads the old element

Phase C — CUTOVER (read switch)
  - New code reads from the new element
  - Old code still writes the old element
  - Monitor for divergence; verify the read path is correct

Phase D — CONTRACT
  - Remove dual-write; new code writes only the new element
  - Drop the old element (column / table) — separate deploy
  - Update the schema docs

Per-change patterns

Add a column

  • A: ALTER TABLE x ADD COLUMN new_col TYPE NULL (NULL allowed; no default to avoid table rewrite on big tables)
  • B: write to both old and new (if replacing); or just start using new
  • C: read from new
  • D: drop old (if applicable)

Rename a column

  • A: ALTER TABLE x ADD COLUMN new_name TYPE (add new)
  • B: dual-write old + new; backfill (UPDATE x SET new_name = old_name in batches)
  • C: read switches to new
  • D: drop old, rename if desired (ALTER COLUMN ... RENAME if portable)

Change a column type

  • A: add new typed column (alter table x add column new_col NEW_TYPE)
  • B: dual-write with conversion; backfill
  • C: read from new
  • D: drop old

Split a table

  • A: create new tables
  • B: dual-write to new tables; backfill
  • C: read switches to new tables
  • D: drop old table

Drop a column

  • A: stop reading from it (code change first)
  • B: stop writing to it (next deploy)
  • C: verify no references
  • D: drop the column

Per-DB specifics

Postgres

  • ALTER TABLE ADD COLUMN is fast IF no default + NULL allowed. Avoid NOT NULL DEFAULT 'x' on big tables — it rewrites.
  • Concurrent indexes: CREATE INDEX CONCURRENTLY — doesn't block writes.
  • Long-running migrations: use lock_timeout and statement_timeout to avoid blocking pile-ups.
  • Backfill: UPDATE ... WHERE id BETWEEN N AND N+1000 in batches; commit per batch.

MySQL

  • pt-online-schema-change for big tables (Percona toolkit).
  • gh-ost for low-impact schema changes (GitHub's tool).
  • Native ALGORITHM=INPLACE, LOCK=NONE available for some changes in MySQL 8.

Aurora / DynamoDB / Mongo / etc.

  • Apply the same expand/contract logic; the primitives differ.

CI gates

  • Migration files require a corresponding reverse migration OR explicit "no-rollback; data-loss" tag
  • Migrations touching large tables (>100k rows) require CONCURRENTLY or pt-osc/gh-ost
  • Phase-A and Phase-D are separate PRs (don't combine; each deploys independently)
  • Spec's Rollout section lists the four phases with target ship dates

Hard rules

  • Never combine phases in one deploy. Each phase is a separate code change + deploy + verify cycle.
  • Always have a reverse migration for Phase A and Phase D (Phase B/C are code-only).
  • Backfill in batches. Big single-transaction backfills lock tables.
  • Monitor during cutover. Watch the read/write divergence at Phase C.
  • Document. Each migration touches an ADR explaining why.

References

  • Square Engineering — "Zero downtime migrations" (canonical)
  • Stripe — "Online schema migrations" blog series
  • gh-ost README — https://github.com/github/gh-ost
  • See also: /upgrade command, .claude/rules/backend.md

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.