agentleFS
kakarot-oncloudkakarot-oncloud/claude-dev-skills/skills/migration-planner/SKILL.md

migration-planner

Skill0 starsChanged 7 months agoMITView on GitHub

Plans database schema migrations safely — produces up/down SQL, identifies risky operations (locks, downtime, data loss), and suggests zero-downtime patterns (expand/contract, backfills, dual-writes). Use this skill when the user asks to "add a column", "rename a table", "change a constraint", needs a migration script, or asks how to migrate without downtime.

  • Deletes or force-pushes

5 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

3 rules. 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 5 edited versions we read keep these.

  • 2

    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. Distinctive:

    Expand: add the new column/table alongside the old.

    line 61
  2. Very specific:

    Never UPDATE huge_table SET ...

    line 71
  3. Distinctive:

    Recommend testing on a prod-sized snapshot: before any operation touching > 1M rows.

    line 98

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

Migration Planner

You plan database schema changes that ship safely to production.

Default dialect

PostgreSQL unless specified. Call out dialect-specific risk (MySQL ALTER TABLE locking behavior differs significantly).

Output template

## Goal
<one sentence: what changes>

## Risk assessment
- Lock duration: <none / brief / blocking — and on what tables>
- Downtime required: <yes / no>
- Reversible: <yes / no, until X>
- Data loss risk: <none / partial / full>

## Up migration
```sql
<DDL/DML in order>

Down migration

<reverse>

Rollout plan

  1. <step>
  2. <step>

Verification

  • <query to confirm new state>
  • <query to confirm old data preserved>

## Risk matrix

| Operation | Risk | Mitigation |
|---|---|---|
| `ADD COLUMN` (nullable, no default) | Low | Direct |
| `ADD COLUMN NOT NULL DEFAULT` | High on large tables (rewrites table in older Postgres / MySQL) | Add nullable → backfill → set NOT NULL |
| `DROP COLUMN` | Medium (irreversible, breaks readers still selecting it) | Stop reading first, deploy, then drop |
| `RENAME COLUMN` | High (atomic break) | Add new → dual-write → backfill → switch reads → drop old |
| `CHANGE TYPE` | High (rewrites + may fail on existing data) | New column + backfill + switch |
| `ADD INDEX` | High lock on MySQL, low on Postgres with `CONCURRENTLY` | Use `CREATE INDEX CONCURRENTLY` (Postgres) |
| `ADD FOREIGN KEY` | High (validates all rows) | Add `NOT VALID` → `VALIDATE CONSTRAINT` separately |
| `DROP TABLE` | Catastrophic if wrong | Rename first, drop later |

## Zero-downtime patterns

### Expand / Contract (the safe rename)
1. **Expand**: add the new column/table alongside the old.
2. **Dual-write**: app writes both old and new.
3. **Backfill**: copy historical data in batches.
4. **Switch reads**: app reads from new.
5. **Stop dual-write**: app writes only to new.
6. **Contract**: drop old column/table.

Each step deploys independently. Stop at any point and roll back without data loss.

### Backfill in batches
Never `UPDATE huge_table SET ...` in one statement — locks and bloats. Use:
```sql
-- Postgres
DO $$
DECLARE
  batch_size INT := 1000;
  rows_updated INT;
BEGIN
  LOOP
    UPDATE huge_table
    SET new_col = old_col
    WHERE id IN (
      SELECT id FROM huge_table WHERE new_col IS NULL LIMIT batch_size
    );
    GET DIAGNOSTICS rows_updated = ROW_COUNT;
    EXIT WHEN rows_updated = 0;
    PERFORM pg_sleep(0.1);
  END LOOP;
END $$;

Rules

  1. Always provide a down migration, even if it's a no-op (note why).
  2. Flag irreversible operations in bold red prose.
  3. Never combine destructive and additive in one migration — split them.
  4. Wrap in a transaction (BEGIN; ... COMMIT;) when the dialect supports DDL transactions (Postgres yes, MySQL mostly no).
  5. Recommend testing on a prod-sized snapshot before any operation touching > 1M rows.
  6. For app-coupled changes, specify the deploy order: code-then-migration or migration-then-code.

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.