| applyTo | src/models/**/*.ts |
|---|
When working with database models in this project:
- Use Prisma schema definitions in
prisma/schema.prisma - Include JSDoc comments with field descriptions
- Define relationships explicitly with
@relation - Add indexes for foreign keys
- Use snake_case for database column names, camelCase in TypeScript
- Always include audit fields:
createdAtandupdatedAt
/**
* User account with authentication and profile information
*/
model User {
id String @id @default(uuid())
email String @unique
name String
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
// Relationships
posts Post[]
comments Comment[]
@@map("users")
@@index([email])
}
/**
* Blog post created by a user
*/
model Post {
id String @id @default(uuid())
title String
content String @db.Text
published Boolean @default(false)
authorId String @map("author_id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
// Relationships
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
comments Comment[]
@@map("posts")
@@index([authorId])
@@index([published, createdAt])
}- Generate migrations with:
npx prisma migrate dev --name descriptive_name - Review generated SQL before applying
- Test migrations on development database first
- Always include rollback plan in migration PR description