2025-09-19 22:59:34 +08:00

75 lines
1.9 KiB
Plaintext

// Prisma schema for circuit-virtual-lab-server
// PostgreSQL provider, use DATABASE_URL from .env
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id String @id @default(cuid())
username String @unique
password String // bcrypt hash
avatar Bytes? // store binary avatar
avatarMime String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
models CircuitModel[]
comments Comment[]
ratings Rating[]
}
model CircuitModel {
id String @id @default(cuid())
title String
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
authorId String
desc String // markdown
brief String? // short summary for listings
model Json // JSON model data
preview Bytes? // binary preview image
previewMime String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
comments Comment[]
ratings Rating[]
@@index([authorId])
@@index([createdAt])
}
model Comment {
id String @id @default(cuid())
model CircuitModel @relation(fields: [modelId], references: [id], onDelete: Cascade)
modelId String
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
authorId String
content String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([modelId])
@@index([authorId])
@@index([createdAt])
}
model Rating {
id String @id @default(cuid())
model CircuitModel @relation(fields: [modelId], references: [id], onDelete: Cascade)
modelId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
value Int // 1-5
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([modelId, userId])
@@index([modelId])
@@index([userId])
}