agentleFS
kasimmjkasimmj/claude-skills-mega/skills/db-migrate/SKILL.md

db-migrate

Skill1 starsChanged 6 months agoMITView on GitHub

Generate safe, reversible SQL migrations with proper up/down statements, transactional wrappers, and rollback safety checks. Supports Postgres, MySQL, SQLite.

18 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use react-query-best-practices, you-might-not-need-a-callback and 8 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.
  • bibektimilsina00Skill

    react-query-best-practices

    Audit and fix React Query usage in apps/web — enforce query key factories, signal forwarding, staleTime, and proper mutation patterns. Use when reviewing or fixing server-state code.

    Also in 3 projects that use this

  • bibektimilsina00Skill

    you-might-not-need-a-callback

    Analyze and fix useCallback anti-patterns in your code

    Also in 3 projects that use this

  • MicrosoftSkill

    cleanup

    Also in 3 projects that use this

  • AWSSkill

    ship

    Finalize dev work on an issue branch — update docs, push, and open a PR.

    Also in 7 projects that use this

  • VercelSkill

    deploy

    Deploy applications to Vercel. Use when the user says "deploy", "deploy to Vercel", "push to production", "deploy my app", or "go live".

    Also in 4 projects that use this

  • SentrySkill

    commit

    Create commit messages following Sentry conventions. Use when committing code changes, writing commit messages, or formatting git history. Follows conventional commits with Sentry-specific issue references.

    Also in 3 projects that use this

  • +3 more from bibektimilsina00

The file

We split this skill into the rules it gives an agent

7 rules. 0 are common, 6 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 13 edited versions we read keep these.

  • 6

    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:

    Look for these markers (in order):

    line 22
  2. Distinctive:

    If you can't tell, ask before writing.

    line 27
  3. Distinctive:

    Use git log and the existing migrations dir to determine the convention.

    line 36
  4. Distinctive:

    Document this in a comment block.

    line 51
  5. Distinctive:

    Add new column, copy data

    line 55
  6. Distinctive:

    Update code to use new column

    line 56
  7. Very specific:

    Use ON DELETE strategy explicitly.

    line 64

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

You are generating a database migration. Migrations must be reversible, safe under concurrent writes, and idempotent where possible.

Step 1 — Detect the migration tool

Look for these markers (in order):

  • migrations/ or db/migrate/ directory
  • Tool config files: knexfile.*, alembic.ini, migrate.yaml, prisma/schema.prisma, supabase/migrations/
  • ORM clues in package.json, requirements.txt, go.mod

If you can't tell, ask before writing.

Step 2 — Compute the next filename

Standard formats:

  • YYYYMMDDHHmmss_<slug>.sql (Supabase, Knex)
  • 001_<slug>.sql (sequential)
  • <n>_<slug>.{up,down}.sql (separate files)

Use git log and the existing migrations dir to determine the convention. Never break the existing pattern.

Step 3 — Write the migration

For each operation, follow these safety rules:

Adding a column

  • ✅ ADD COLUMN ... NULL DEFAULT <value> — safe
  • ❌ ADD COLUMN ... NOT NULL without default — breaks on large tables
  • ✅ Two-step: add nullable → backfill in batches → add NOT NULL constraint

Removing a column

  • 🚨 Two-deploy approach required:
    1. Deploy code that stops reading/writing the column
    2. Then drop it in a follow-up migration
  • Document this in a comment block.

Renaming a column

  • 🚨 Three-step approach:
    1. Add new column, copy data
    2. Update code to use new column
    3. Drop old column

Adding an index

  • ✅ CREATE INDEX CONCURRENTLY on Postgres for tables > 1M rows
  • ❌ Regular CREATE INDEX will lock the table

Foreign keys

  • Use ON DELETE strategy explicitly. Never default.

Step 4 — Provide rollback

For each up, write the inverse down. If the down would lose data, say so explicitly in a comment.

-- up
ALTER TABLE users ADD COLUMN email_verified BOOLEAN DEFAULT FALSE;

-- down
-- ⚠️ This is destructive — deleted rows can't be recovered.
ALTER TABLE users DROP COLUMN email_verified;

Step 5 — Wrap in a transaction (where possible)

  • Postgres/SQLite: wrap in BEGIN; ... COMMIT;
  • MySQL: most DDL is implicit-commit; warn the user.
  • Statements that cannot be in a transaction (e.g., CREATE INDEX CONCURRENTLY) go in their own migration file.

Step 6 — Hand off

Print:

  • The file path created
  • The exact command to apply (npm run migrate, alembic upgrade head, supabase migration up)
  • The exact rollback command

When NOT to use

  • Seeding test data (use a fixture skill instead)
  • ORM-driven schema changes that are auto-generated (Prisma migrate, ActiveRecord)
  • Stored procedure-only changes (use stored-proc skill if available)

Failure modes

  • ⚠️ Backfills against tables > 10M rows should be done outside the migration in a chunked job. Suggest this when relevant.
  • ⚠️ Always recommend running migrations on a staging copy first.

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.