Database migration
Applied migrations are immutable history. This skill exists so nobody ever "just edits the SQL file".
Steps
- Ask the user first. Schema changes are on the ASK FIRST list in AGENTS.md. Describe the change and why.
- Edit
src/db/schema.tsonly. Conventions:- Every foreign key gets an index.
- Timestamps:
createdAtwithdefaultNow(), timezone-aware. - Money in integer cents; credits in integers.
- Enums via
pgEnum, named<table>_<column>.
- Generate:
pnpm db:generate. Never write migration SQL by hand. - Read the generated file in
drizzle/. Confirm: no unintendedDROP, 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. - Apply locally:
pnpm db:migrate(Postgres running viadocker compose up -d). - Run
pnpm test— the ledger suite will catch schema drift in credit tables. - Commit
src/db/schema.tsand the newdrizzle/files together.
Never
- Edit or delete an existing file in
drizzle/. - Run
drizzle-kit pushagainst anything but a throwaway local DB — this repo uses generated, committed migrations. - Touch
credit_transactionssemantics (signed integer amounts, UNIQUEidempotencyKey) without reading.claude/rules/billing.md.


