agentleFS
nikandr-surkovnikandr-surkov/ai-saas-starter/.claude/skills/db-migration/SKILL.md

db-migration

Skill23 starsChanged 5 months agoMITView on GitHub

Make a database schema change safely — edit schema.ts, generate the migration, review the SQL, apply it. Use for any change under src/db/.

6 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

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

  • 0

    Common

    Most of the 5 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Every foreign key gets an index.

    line 16
  2. Very specific:

    Run pnpm test — the ledger suite will catch schema drift in credit tables.

    line 27
  3. Very specific:

    Commit src/db/schema.ts and the new drizzle/ files together.

    line 29
  4. Very specific:

    Run drizzle-kit push against anything but a throwaway local DB — this repo uses generated, committed migrations.

    line 34

“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

Database migration

Applied migrations are immutable history. This skill exists so nobody ever "just edits the SQL file".

Steps

  1. Ask the user first. Schema changes are on the ASK FIRST list in AGENTS.md. Describe the change and why.
  2. Edit src/db/schema.ts only. Conventions:
    • Every foreign key gets an index.
    • Timestamps: createdAt with defaultNow(), timezone-aware.
    • Money in integer cents; credits in integers.
    • Enums via pgEnum, named <table>_<column>.
  3. Generate: pnpm db:generate. Never write migration SQL by hand.
  4. Read the generated file in drizzle/. Confirm: no unintended DROP, correct column types/defaults, indexes present. Column renames often generate drop+create — if data must survive, say so and write the migration plan out for the user before applying.
  5. Apply locally: pnpm db:migrate (Postgres running via docker compose up -d).
  6. Run pnpm test — the ledger suite will catch schema drift in credit tables.
  7. Commit src/db/schema.ts and the new drizzle/ files together.

Never

  • Edit or delete an existing file in drizzle/.
  • Run drizzle-kit push against anything but a throwaway local DB — this repo uses generated, committed migrations.
  • Touch credit_transactions semantics (signed integer amounts, UNIQUE idempotencyKey) without reading .claude/rules/billing.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.