Skip to content
Agentmart
Submit a tool

safe-migration

Plan and write zero-downtime database and schema migrations.

Skill by shankarr1503

IndexedMIT
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/shankarr1503-safe-migration

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Plan and write zero-downtime database and schema migrations. Use when adding, renaming or removing columns, tables or indexes, changing types or constraints, backfilling data, or changing message/API schemas that live systems depend on. Uses expand-and-contract and makes every step reversible.

Use cases: documents, backend, data, writing

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/safe-migration

What's inside

Skill name
safe-migration
Description
Plan and write zero-downtime database and schema migrations. Use when adding, renaming or removing columns, tables or indexes, changing types or constraints, backfilling data, or changing message/API schemas that live systems depend on. Uses expand-and-contract and makes every step reversible.
License
MIT
Instructions
46 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

# Safe migration

During a deploy, old and new code run against the same database at the same time. Every migration must work with **both**.

## The rule: expand, migrate, contract

Never rename or drop in one step. Split into separately deployed phases:

1. **Expand** — add the new thing (column, table, index), nullable or with a safe default. Old code ignores it.
2. **Dual-write** — deploy code that writes both old and new; reads still use old.
3. **Backfill** — copy existing data in batches.
4. **Switch reads** — deploy code reading the new thing. Verify.
5. **Contract** — stop writing the old thing, then drop it in a later release once nothing references it.

A rename is "add new + copy + switch + drop old", never `RENAME COLUMN` on a live table used by running code.

## Locking and size hazards

Know your database's behavior; check the docs for your version. Common traps:

- **Postgres:** create indexes with `CREATE INDEX CONCURRENTLY` (outside a transaction). Add foreign keys and check constraints as `NOT VALID`, then `VALIDATE` separately. Adding a column with a volatile default or changing a column type can rewrite the table. Set `lock_timeout` so a migration waiting on a lock does not block all traffic behind it.
- **MySQL:** check whether the ALTER is `INSTANT`/`INPLACE` or copies the table; use online schema change tools (gh-ost, pt-osc) for large tables.
- **Any database:** `NOT NULL` on an existing column requires a backfill first; unique constraints fail if duplicates exist — check before.

## Backfills

- Batch by primary key range (e.g. 1–10k rows per batch), commit per batch, sleep between batches, and make it resumable and idempotent.
- Dual-writes are live during the backfill, so a batch must not overwrite newer data: update only rows still unmigrated (`WHERE new_col IS NULL`), or compare a version/`updated_at` column in the same statement. Verify that writes made during the backfill survive it.
- Never one giant `UPDATE` on a large table — it holds locks, bloats, and replicates slowly.
- Measure row counts before and after; verify with a query that finds unmigrated rows.

## Every migration needs

- A tested **down/rollback** path, or an explicit note that it is irreversible and why that is acceptable.
- A dry run against a production-sized copy or at least realistic data volumes, with the time it took.
- Separation from application code changes when ordering matters (schema first, code second; or the reverse for contract steps).

## Non-database schemas

The same rules apply to API responses, event/message formats, protobuf/Avro schemas and config files: add optional fields first, keep readers tolerant of unknown and missing fields, never reuse a removed field's name/number, and remove only after every producer and consumer has moved.

## Output

A phase-by-phase plan (what ships in each deploy), the migration files, lock/duration risk per step, verification queries, and rollback steps.

From shankarr1503/omnistack, MIT.

More from shankarr1503/omnistack

Signals

Stars
0
Forks
0
Open issues
0
Last commit (this folder)
Oct 7, 2026 (22 days ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from shankarr1503

Cite this page

safe-migration skill. Agent Mart. https://agentmart.dev/skills/shankarr1503-safe-migration (last updated 2026-10-24)