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[] @@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[] @@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) 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) @@index([chatId, createdAt, id]) @@index([senderId]) @@map("messages") }