mirror of
https://git.meshkee.com/Meshkee/backend.git
synced 2026-08-11 22:30:59 +04:30
NestJS backend with Prisma, Docker Compose for Postgres/Redis, and deploy docs for the production VM.
34 lines
1009 B
Plaintext
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.
|