Database schema change
Change requested: $ARGUMENTS
The only correct flow
- Edit
packages/db/src/schema.ts— the single source of truth (~30pgTables +pgEnums). Match existing naming, enum reuse,references()relations, and timestamp conventions. Enums shared with the app mirror@skillist/contracts— keep them in sync. pnpm db:generate— drizzle-kit writes SQL topackages/db/drizzle/NNNN_*.sqland updatesmeta/_journal.json.pnpm db:migrate— applies againstDATABASE_URLfrom the root.env.
Rules
- 🚫 Never hand-edit
packages/db/drizzle/— it's generated and Biome-ignored. Wrong SQL? Fixschema.tsand regenerate. - Prefer additive, backward-compatible changes. For any drop/rename/type-narrow, state the data-loss risk before running
db:migrate. - After changing a table, grep
apps/api/srcfor readers/writers and update contracts + route handlers to match. The Worker reads the schema viacreateWorkerDb(env)over theHYPERDRIVEbinding.
Verify
pnpm typecheck(schema andapps/apitype errors surface here).- If app code changed:
pnpm --filter @skillist/api exec vitest run <path>.
For a non-trivial change spanning tables and call sites, delegate to the db-migrator agent.