--- description: SQL migration and Prisma schema workflow globs: database/**/*,prisma/**/* alwaysApply: false --- # Database Workflow ## Migrations - Raw SQL in `database/migrations/` — numbered files (e.g. `012_feature.sql`) - Apply: `./database/migrate.sh` or `docker exec` into `meshkee-postgres` - Docker auto-runs migrations only on **first** Postgres volume init ## After schema change ```bash npm run prisma:pull npm run prisma:generate ``` Never edit `prisma/schema.prisma` without a corresponding SQL migration (except post-pull formatting). ## Conventions in SQL - `set_updated_at()` triggers on mutable tables - `BIGINT GENERATED BY DEFAULT AS IDENTITY` for PKs - Foreign keys with explicit `ON DELETE` (Cascade for owned data, Restrict/SetNull where appropriate) - Seed permissions in the same migration when adding new resources ## Prisma relations Keep relation names aligned with existing schema style. `businessId` maps to `business_id`, enums use `@@map` for snake_case DB names.