erp_be/.cursor/rules/erp-backend-prisma.mdc
2026-06-17 11:30:11 +05:30

42 lines
1.0 KiB
Plaintext

---
description: Prisma schema and database conventions for ERP backend
globs: prisma/**/*
alwaysApply: false
---
# Prisma & Database Conventions
## Naming
- Models: `PascalCase` singular (e.g. `Vendor`)
- Fields: `snake_case` (match requirements doc — no camelCase mapping)
- Tables: `snake_case` plural via `@@map("vendors")`
## Required columns (every business table)
```
is_active, created_by, updated_by, created_at, updated_at, deleted_at
```
## Patterns
- Primary keys: `BigInt @id @default(autoincrement())`
- Soft delete everywhere on transactional tables
- Document numbering via `document_series` + atomic increment in `generateCode.js`
- Seed idempotently with `upsert` — modules, permissions, roles, bootstrap Super Admin
## Migration workflow
```bash
npx prisma migrate dev --name <description>
npx prisma generate
node prisma/seed.js
```
## When adding a new table
1. Add model with common columns + `@@map`
2. Create migration
3. Update seed if new module/permissions needed
4. Add service with `deleted_at: null` filters and audit logging