forked from mtusi2026/mtusi2026lab5
216 lines
7.8 KiB
Plaintext
216 lines
7.8 KiB
Plaintext
generator client {
|
|
provider = "prisma-client"
|
|
output = "../src/generated/prisma"
|
|
moduleFormat = "cjs"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
}
|
|
|
|
model User {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
username String @unique @db.VarChar(32)
|
|
displayName String @map("display_name") @db.VarChar(100)
|
|
passwordHash String? @map("password_hash")
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
|
chatsEpoch BigInt @default(0) @map("chats_epoch")
|
|
memberships ChatMember[]
|
|
messages Message[]
|
|
sessions Session[]
|
|
idempotencyRecords MessageIdempotency[]
|
|
attachments Attachment[]
|
|
directUploads DirectUpload[]
|
|
|
|
@@map("users")
|
|
}
|
|
|
|
model Session {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
userId String @map("user_id") @db.Uuid
|
|
tokenHash String @unique @map("token_hash") @db.Char(64)
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
|
expiresAt DateTime @map("expires_at") @db.Timestamptz(3)
|
|
revokedAt DateTime? @map("revoked_at") @db.Timestamptz(3)
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([userId])
|
|
@@index([expiresAt])
|
|
@@map("sessions")
|
|
}
|
|
|
|
model Chat {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
title String @db.VarChar(100)
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
|
messageEpochs ChatMessageEpoch[]
|
|
members ChatMember[]
|
|
messages Message[]
|
|
idempotencyRecords MessageIdempotency[]
|
|
attachments Attachment[]
|
|
directUploads DirectUpload[]
|
|
|
|
@@index([createdAt, id])
|
|
@@map("chats")
|
|
}
|
|
|
|
model ChatMember {
|
|
chatId String @map("chat_id") @db.Uuid
|
|
userId String @map("user_id") @db.Uuid
|
|
position Int
|
|
chat Chat @relation(fields: [chatId], references: [id], onDelete: Cascade)
|
|
user User @relation(fields: [userId], references: [id], onDelete: Restrict)
|
|
|
|
@@id([chatId, userId])
|
|
@@unique([chatId, position])
|
|
@@index([userId, chatId])
|
|
@@map("chat_members")
|
|
}
|
|
|
|
model ChatMessageEpoch {
|
|
chatId String @map("chat_id") @db.Uuid
|
|
bucket Int @db.SmallInt
|
|
epoch BigInt @default(0)
|
|
chat Chat @relation(fields: [chatId], references: [id], onDelete: Cascade)
|
|
|
|
@@id([chatId, bucket])
|
|
@@map("chat_message_epochs")
|
|
}
|
|
|
|
model Message {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
chatId String @map("chat_id") @db.Uuid
|
|
senderId String @map("sender_id") @db.Uuid
|
|
text String @db.VarChar(4000)
|
|
attachmentIds String[] @default([]) @map("attachment_ids") @db.Uuid
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
|
chat Chat @relation(fields: [chatId], references: [id], onDelete: Cascade)
|
|
sender User @relation(fields: [senderId], references: [id], onDelete: Restrict)
|
|
idempotencyRecords MessageIdempotency[]
|
|
|
|
@@index([chatId, createdAt, id])
|
|
@@index([senderId])
|
|
@@map("messages")
|
|
}
|
|
|
|
enum AttachmentStatus {
|
|
queued
|
|
processing
|
|
ready
|
|
failed
|
|
|
|
@@map("attachment_status")
|
|
}
|
|
|
|
model Attachment {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
chatId String @map("chat_id") @db.Uuid
|
|
ownerId String @map("owner_id") @db.Uuid
|
|
objectKey String @unique @map("object_key")
|
|
filename String @db.VarChar(255)
|
|
contentType String @map("content_type") @db.VarChar(32)
|
|
sizeBytes Int @map("size_bytes")
|
|
sha256 String @db.Char(64)
|
|
status AttachmentStatus @default(ready)
|
|
errorCode String? @map("error_code")
|
|
thumbnailSize Int? @map("thumbnail_size")
|
|
thumbnailWidth Int? @map("thumbnail_width")
|
|
thumbnailHeight Int? @map("thumbnail_height")
|
|
thumbnailSha256 String? @map("thumbnail_sha256") @db.Char(64)
|
|
cropSize Int? @map("crop_size")
|
|
cropSha256 String? @map("crop_sha256") @db.Char(64)
|
|
optimizedSize Int? @map("optimized_size")
|
|
optimizedWidth Int? @map("optimized_width")
|
|
optimizedHeight Int? @map("optimized_height")
|
|
optimizedSha256 String? @map("optimized_sha256") @db.Char(64)
|
|
publishedAt DateTime? @map("published_at") @db.Timestamptz(3)
|
|
leaseUntil DateTime? @map("lease_until") @db.Timestamptz(3)
|
|
nextAttemptAt DateTime? @map("next_attempt_at") @db.Timestamptz(3)
|
|
failedAt DateTime? @map("failed_at") @db.Timestamptz(3)
|
|
replayUntil DateTime? @map("replay_until") @db.Timestamptz(3)
|
|
generation Int @default(0)
|
|
failures Int @default(0)
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
|
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(3)
|
|
chat Chat @relation(fields: [chatId], references: [id], onDelete: Restrict)
|
|
owner User @relation(fields: [ownerId], references: [id], onDelete: Restrict)
|
|
replays AttachmentReplay[]
|
|
outbox AttachmentOutbox[]
|
|
|
|
@@index([chatId])
|
|
@@index([ownerId])
|
|
@@index([status, failedAt, id])
|
|
@@map("attachments")
|
|
}
|
|
|
|
model AttachmentOutbox {
|
|
attachmentId String @map("attachment_id") @db.Uuid
|
|
generation Int
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
|
attachment Attachment @relation(fields: [attachmentId], references: [id], onDelete: Restrict)
|
|
|
|
@@id([attachmentId, generation])
|
|
@@index([createdAt, attachmentId, generation])
|
|
@@map("attachment_outbox")
|
|
}
|
|
|
|
model AttachmentReplay {
|
|
attachmentId String @map("attachment_id") @db.Uuid
|
|
requestId String @map("request_id") @db.Uuid
|
|
operator String @db.VarChar(128)
|
|
generation Int
|
|
errorCode String? @map("error_code")
|
|
failures Int
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
|
attachment Attachment @relation(fields: [attachmentId], references: [id], onDelete: Restrict)
|
|
|
|
@@id([attachmentId, requestId])
|
|
@@map("attachment_replays")
|
|
}
|
|
|
|
enum DirectUploadStatus {
|
|
pending
|
|
completed
|
|
rejected
|
|
expired
|
|
|
|
@@map("direct_upload_status")
|
|
}
|
|
|
|
model DirectUpload {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
chatId String @map("chat_id") @db.Uuid
|
|
ownerId String @map("owner_id") @db.Uuid
|
|
filename String @db.VarChar(255)
|
|
contentType String @map("content_type") @db.VarChar(32)
|
|
sizeBytes Int @map("size_bytes")
|
|
sha256 String @db.Char(64)
|
|
status DirectUploadStatus @default(pending)
|
|
expiresAt DateTime @map("expires_at") @db.Timestamptz(3)
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
|
chat Chat @relation(fields: [chatId], references: [id], onDelete: Restrict)
|
|
owner User @relation(fields: [ownerId], references: [id], onDelete: Restrict)
|
|
|
|
@@index([status, expiresAt])
|
|
@@index([chatId])
|
|
@@index([ownerId])
|
|
@@map("direct_uploads")
|
|
}
|
|
|
|
model MessageIdempotency {
|
|
userId String @map("user_id") @db.Uuid
|
|
chatId String @map("chat_id") @db.Uuid
|
|
key String @db.VarChar(128)
|
|
messageId String? @map("message_id") @db.Uuid
|
|
expiresAt DateTime @map("expires_at") @db.Timestamptz(3)
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
chat Chat @relation(fields: [chatId], references: [id], onDelete: Cascade)
|
|
message Message? @relation(fields: [messageId], references: [id], onDelete: Cascade)
|
|
|
|
@@id([userId, chatId, key])
|
|
@@index([chatId])
|
|
@@index([messageId])
|
|
@@index([expiresAt])
|
|
@@map("message_idempotency")
|
|
}
|