56 lines
1.6 KiB
Plaintext
56 lines
1.6 KiB
Plaintext
generator client {
|
|
provider = "prisma-client"
|
|
output = "../generated/prisma"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "sqlite"
|
|
}
|
|
|
|
generator prismabox {
|
|
provider = "prismabox"
|
|
typeboxImportDependencyName = "elysia"
|
|
typeboxImportVariableName = "t"
|
|
inputModel = true
|
|
output = "../generated/prismabox"
|
|
}
|
|
|
|
model User {
|
|
id String @id @default(cuid())
|
|
email String @unique
|
|
username String @unique
|
|
password String
|
|
createdAt DateTime @default(now())
|
|
messages Message[] @relation("UserMessages")
|
|
conversationMemberships ConversationParticipant[] @relation("UserConversations")
|
|
}
|
|
|
|
model Conversation {
|
|
id String @id @default(cuid())
|
|
createdAt DateTime @default(now())
|
|
participants ConversationParticipant[] @relation("ConversationParticipants")
|
|
messages Message[] @relation("ConversationMessages")
|
|
}
|
|
|
|
model ConversationParticipant {
|
|
id String @id @default(cuid())
|
|
conversationId String
|
|
userId String
|
|
conversation Conversation @relation("ConversationParticipants", fields: [conversationId], references: [id], onDelete: Cascade)
|
|
user User @relation("UserConversations", fields: [userId], references: [id], onDelete: Cascade)
|
|
lastReadAt DateTime?
|
|
@@unique([conversationId, userId])
|
|
@@index([userId])
|
|
}
|
|
|
|
model Message {
|
|
id String @id @default(cuid())
|
|
conversationId String
|
|
senderId String
|
|
content String
|
|
createdAt DateTime @default(now())
|
|
conversation Conversation @relation("ConversationMessages", fields: [conversationId], references: [id], onDelete: Cascade)
|
|
sender User @relation("UserMessages", fields: [senderId], references: [id], onDelete: Cascade)
|
|
@@index([conversationId, createdAt])
|
|
}
|