Files
backend/.cursor/rules/database-migrations.mdc
T
Ali Reza bb59d5e9ba Initial commit: Meshkee CMS API
NestJS backend with Prisma, Docker Compose for Postgres/Redis, and deploy docs for the production VM.
2026-07-21 17:52:36 +03:30

34 lines
1009 B
Plaintext

---
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.