Prisma Rules
Tech Stack
- •Database: PostgreSQL running on RDS
- •Prisma v2
Naming Conventions
- •Tables are named with TitleCase
- •Columns are named with camelCase
- •Tables are singular, e.g. "User" not "Users"
- •Never use GraphQL built-in type names as tables (e.g.,
Subscription,Query,Mutation)
By type
- •Boolean: Start with
is,can,are(e.g.,isActive) - •Date: End with
At(e.g.,createdAt) - •Array: Use plural form (e.g.,
users) - •Enums: Use TitleCase (e.g.,
OrganizationKind)
Standard Model Structure
- •Every model has:
id,createdAt,updatedAt - •User-owned entities have:
userIdanduserrelation - •Org-owned entities have:
orgIdandorgrelation
Relations
- •Foreign keys end with
Id(e.g.,userId,stateId) - •Relation fields omit the
Idsuffix (e.g.,user,state) - •Use
@uniquewhere applicable - •Add
onDelete: Cascadefor dependent entities - •Do NOT use @relation
nameunless we have too, aka +1 relations to the same table
Status Enums
- •Status enums follow pattern:
EntityNameStatus(e.g.,ProductStatus,ReceiptStatus) - •Common status values:
Draft,Pending,Active,Archived - •Use
@default()for initial status
Indexes
- •Add indexes for: foreign keys, status fields, date fields, commonly filtered fields
- •Don't create indexes for columns that are already
@uniqueor@id
Column order and grouping
Requires a new line after each group
- •id, createdAt, updatedAt, userId/user (if exists), orgId/org (if exists)
- •All non-relational columns
- •One group per relation: xId field first, then x relation field, blank line before next relation
- •All list relations (users[], payments[], etc.)
- •@@unique lines, then @@index lines come last