feat: add attachments schema with ordered message links

This commit is contained in:
2026-11-05 14:21:13 +03:00
parent 51f4adfd58
commit d960734dae
3 changed files with 87 additions and 5 deletions
+41 -5
View File
@@ -16,6 +16,7 @@ model User {
memberships ChatMember[]
messages Message[]
sessions Session[]
attachments Attachment[]
@@map("users")
}
@@ -32,11 +33,12 @@ model Session {
}
model Chat {
id String @id @default(uuid()) @db.Uuid
title String @db.VarChar(100)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
members ChatMember[]
messages Message[]
id String @id @default(uuid()) @db.Uuid
title String @db.VarChar(100)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
members ChatMember[]
messages Message[]
attachments Attachment[]
@@map("chats")
}
@@ -61,11 +63,45 @@ model Message {
chat Chat @relation(fields: [chatId], references: [id], onDelete: Cascade)
sender User @relation(fields: [senderId], references: [id], onDelete: Restrict)
idempotencyKeys IdempotencyKey[]
attachments MessageAttachment[]
@@index([chatId, createdAt, id])
@@map("messages")
}
model Attachment {
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)
objectKey String @unique @map("object_key") @db.VarChar(128)
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: Cascade)
owner User @relation(fields: [ownerId], references: [id], onDelete: Restrict)
messages MessageAttachment[]
@@index([chatId])
@@index([ownerId])
@@map("attachments")
}
model MessageAttachment {
messageId String @map("message_id") @db.Uuid
position Int @db.SmallInt
attachmentId String @map("attachment_id") @db.Uuid
message Message @relation(fields: [messageId], references: [id], onDelete: Cascade)
attachment Attachment @relation(fields: [attachmentId], references: [id], onDelete: NoAction)
@@id([messageId, position])
@@unique([messageId, attachmentId])
@@index([attachmentId])
@@map("message_attachments")
}
model IdempotencyKey {
userId String @map("user_id") @db.Uuid
chatId String @map("chat_id") @db.Uuid