508903b67d
- #7: SSE events 接口校验 userId 房间成员身份,start() 加 try/catch - #9: Favorite 新增 restaurantId 字段做精确去重,不再用 JSON contains - #10: 补齐 Decision/Favorite/Room/BlindBoxIdea 缺失索引 - #11: Decision/Favorite/BlindBoxMember/BlindBoxIdea 加 onDelete Cascade
103 lines
2.7 KiB
Plaintext
103 lines
2.7 KiB
Plaintext
datasource db {
|
|
provider = "sqlite"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
model Room {
|
|
id String @id
|
|
data String
|
|
createdAt DateTime @default(now())
|
|
expiresAt DateTime
|
|
|
|
@@index([expiresAt])
|
|
}
|
|
|
|
model User {
|
|
id String @id @default(cuid())
|
|
username String @unique
|
|
passwordHash String
|
|
avatar String @default("🐱")
|
|
email String? @unique
|
|
preferences String @default("{}")
|
|
createdAt DateTime @default(now())
|
|
decisions Decision[]
|
|
favorites Favorite[]
|
|
|
|
createdBlindBoxRooms BlindBoxRoom[] @relation("RoomCreator")
|
|
blindBoxMemberships BlindBoxMember[]
|
|
submittedIdeas BlindBoxIdea[] @relation("IdeaSubmitter")
|
|
drawnIdeas BlindBoxIdea[] @relation("IdeaDrawer")
|
|
}
|
|
|
|
model Decision {
|
|
id String @id @default(cuid())
|
|
userId String
|
|
roomId String
|
|
restaurantName String
|
|
restaurantData String
|
|
matchType String
|
|
participants Int
|
|
createdAt DateTime @default(now())
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([userId])
|
|
@@index([roomId])
|
|
}
|
|
|
|
model Favorite {
|
|
id String @id @default(cuid())
|
|
userId String
|
|
restaurantId String @default("")
|
|
restaurantData String
|
|
createdAt DateTime @default(now())
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([userId, restaurantId])
|
|
@@index([userId])
|
|
}
|
|
|
|
model BlindBoxRoom {
|
|
id String @id @default(cuid())
|
|
code String @unique
|
|
name String
|
|
creatorId String
|
|
createdAt DateTime @default(now())
|
|
|
|
creator User @relation("RoomCreator", fields: [creatorId], references: [id])
|
|
members BlindBoxMember[]
|
|
ideas BlindBoxIdea[]
|
|
}
|
|
|
|
model BlindBoxMember {
|
|
id String @id @default(cuid())
|
|
roomId String
|
|
userId String
|
|
joinedAt DateTime @default(now())
|
|
|
|
room BlindBoxRoom @relation(fields: [roomId], references: [id], onDelete: Cascade)
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([roomId, userId])
|
|
}
|
|
|
|
model BlindBoxIdea {
|
|
id String @id @default(uuid())
|
|
roomId String
|
|
userId String
|
|
content String
|
|
status String @default("in_pool")
|
|
drawnById String?
|
|
createdAt DateTime @default(now())
|
|
|
|
room BlindBoxRoom @relation(fields: [roomId], references: [id], onDelete: Cascade)
|
|
user User @relation("IdeaSubmitter", fields: [userId], references: [id], onDelete: Cascade)
|
|
drawnBy User? @relation("IdeaDrawer", fields: [drawnById], references: [id], onDelete: SetNull)
|
|
|
|
@@index([roomId, status])
|
|
@@index([userId])
|
|
}
|