nephthys/prisma/schema.prisma
Mish 14784f77d1
Preparation for improving the daily summary message (#124)
* Add lastMsgAt and lastMsgBy to DB

* Keep track of the last messages in threads

* Add UserType enum to schema

* Make both of the new fields optional

* Add data/ to .gitignore

* Only include users who have resolved tickets on the overall leaderboard

Fixes #96

* Fix docstring
2025-11-29 11:25:49 +00:00

115 lines
2.8 KiB
Text

generator client {
provider = "prisma-client-py"
interface = "asyncio"
recursive_type_depth = 5
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
enum TicketStatus {
OPEN
IN_PROGRESS
CLOSED
}
enum UserType {
AUTHOR
HELPER
OTHER
}
model User {
id Int @id @unique @default(autoincrement())
slackId String @unique
username String? @unique
admin Boolean @default(false)
openedTickets Ticket[] @relation("OpenedTickets")
closedTickets Ticket[] @relation("ClosedTickets")
assignedTickets Ticket[] @relation("AssignedTickets")
tagSubscriptions UserTagSubscription[]
helper Boolean @default(false)
createdAt DateTime @default(now())
}
model Ticket {
id Int @id @unique @default(autoincrement())
title String
description String
status TicketStatus @default(OPEN)
// TS for the original help message (top of the help thread)
msgTs String @unique
// TS for the ticket message in the "backend" tickets channel
ticketTs String @unique
// Messages sent by the bot in the help thread
userFacingMsgs BotMessage[]
lastMsgAt DateTime? @default(now())
lastMsgBy UserType? @default(AUTHOR)
openedBy User @relation("OpenedTickets", fields: [openedById], references: [id])
openedById Int
closedBy User? @relation("ClosedTickets", fields: [closedById], references: [id])
closedById Int?
closedAt DateTime?
assignedTo User? @relation("AssignedTickets", fields: [assignedToId], references: [id])
assignedToId Int?
assignedAt DateTime?
tagsOnTickets TagsOnTickets[]
createdAt DateTime @default(now())
}
model Tag {
id Int @id @unique @default(autoincrement())
name String @unique
ticketsOnTags TagsOnTickets[]
userSubscriptions UserTagSubscription[]
createdAt DateTime @default(now())
}
model TagsOnTickets {
ticket Ticket @relation(fields: [ticketId], references: [id], onDelete: Cascade)
ticketId Int
tag Tag @relation(fields: [tagId], references: [id], onDelete: Cascade)
tagId Int
assignedAt DateTime @default(now())
@@id([ticketId, tagId])
@@map("tags_on_tickets")
}
model UserTagSubscription {
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int
tag Tag @relation(fields: [tagId], references: [id], onDelete: Cascade)
tagId Int
subscribedAt DateTime @default(now())
@@id([userId, tagId])
@@map("user_tag_subscriptions")
}
model BotMessage {
id Int @id @unique @default(autoincrement())
ts String
channelId String
ticket Ticket @relation(fields: [ticketId], references: [id], onDelete: Cascade)
ticketId Int
@@unique([ts, channelId])
}