Finish database schema

This commit is contained in:
Isaac 2022-03-22 22:05:22 +00:00
parent e569642240
commit 88782ec1a5
2 changed files with 128 additions and 24 deletions

View File

@ -10,7 +10,64 @@ datasource db {
url = env("DB_CONNECTION_URL") url = env("DB_CONNECTION_URL")
} }
model ArchivedChannel {
channelId String @db.VarChar(19)
name String
ticket Ticket @relation(fields: [ticketId], references: [id])
ticketId String @db.VarChar(19)
@@id([ticketId, channelId])
@@unique([ticketId, channelId])
@@map("archived_channels")
}
model ArchivedMessage {
author ArchivedUser @relation(fields: [ticketId, authorId], references: [ticketId, userId])
authorId String @db.VarChar(19)
data Json
deleted Boolean @default(false)
edited Boolean @default(false)
id String @id @unique @db.VarChar(19)
ticket Ticket @relation(fields: [ticketId], references: [id])
ticketId String @db.VarChar(19)
@@map("archived_messages")
}
model ArchivedRole {
archivedUsers ArchivedUser[]
colour String @default("7289DA") @db.Char(6)
name String
roleId String @db.VarChar(19)
ticket Ticket @relation(fields: [ticketId], references: [id])
ticketId String @db.VarChar(19)
@@id([ticketId, roleId])
@@unique([ticketId, roleId])
@@map("archived_roles")
}
model ArchivedUser {
archivedMessages ArchivedMessage[]
avatar String
bot Boolean @default(false)
discriminator String @db.Char(4)
displayName String
role ArchivedRole @relation(fields: [ticketId, roleId], references: [ticketId, roleId])
roleId String @db.VarChar(19)
ticket Ticket @relation(fields: [ticketId], references: [id])
ticketId String @db.VarChar(19)
userId String @db.VarChar(19)
username String
@@id([ticketId, userId])
@@unique([ticketId, userId])
@@map("archived_users")
}
model Category { model Category {
guild Guild @relation(fields: [guildId], references: [id])
guildId String @db.VarChar(19)
id String @id @unique @db.VarChar(19) id String @id @unique @db.VarChar(19)
tickets Ticket[] tickets Ticket[]
@ -18,17 +75,60 @@ model Category {
} }
model Guild { model Guild {
id String @id @unique @db.VarChar(19) archive Boolean @default(true)
archive Boolean @default(true) categories Category[]
errorColour String @default("RED") errorColour String @default("RED")
primaryColour String @default("#009999") id String @id @unique @db.VarChar(19)
successColour String @default("GREEN") primaryColour String @default("#009999")
successColour String @default("GREEN")
surveys Survey[]
tags Tag[] tags Tag[]
tickets Ticket[] tickets Ticket[]
@@map("guilds") @@map("guilds")
} }
model Survey {
guild Guild @relation(fields: [guildId], references: [id])
guildId String @db.VarChar(19)
name String
questions SurveyQuestion[]
responses SurveyResponse[]
@@id([guildId, name])
@@unique([guildId, name])
@@map("surveys")
}
model SurveyResponse {
answers SurveyQuestionAnswer[]
id Int @id @default(autoincrement())
survey Survey @relation(fields: [surveyGuildId, surveyName], references: [guildId, name])
surveyGuildId String @db.VarChar(19)
surveyName String
@@map("survey_responses")
}
model SurveyQuestion {
content String @db.Text
id Int @id @default(autoincrement())
survey Survey @relation(fields: [surveyGuildId, surveyName], references: [guildId, name])
surveyGuildId String @db.VarChar(19)
surveyName String
@@map("survey_questions")
}
model SurveyQuestionAnswer {
content String @db.Text
id Int @id @default(autoincrement())
surveyResponse SurveyResponse @relation(fields: [surveyResponseId], references: [id])
surveyResponseId Int
@@map("survey_answers")
}
model Tag { model Tag {
content String @db.Text content String @db.Text
guild Guild @relation(fields: [guildId], references: [id]) guild Guild @relation(fields: [guildId], references: [id])
@ -41,25 +141,29 @@ model Tag {
} }
model Ticket { model Ticket {
id String @id @unique @db.VarChar(19) archivedChannels ArchivedChannel[]
category Category @relation(fields: [categoryId], references: [id]) archivedMessages ArchivedMessage[]
categoryId String @db.VarChar(19) archivedRoles ArchivedRole[]
claimedBy User? @relation(name: "ClaimedTickets", fields: [claimedById], references: [id]) archivedUsers ArchivedUser[]
claimedById String @db.VarChar(19) category Category @relation(fields: [categoryId], references: [id])
closedBy User? @relation(name: "ClosedTickets", fields: [closedById], references: [id]) categoryId String @db.VarChar(19)
closedById String @db.VarChar(19) claimedBy User @relation(name: "ClaimedTickets", fields: [claimedById], references: [id])
closedReason String? claimedById String @db.VarChar(19)
createdBy User? @relation(name: "CreatedTickets", fields: [createdById], references: [id]) closedBy User @relation(name: "ClosedTickets", fields: [closedById], references: [id])
createdById String @db.VarChar(19) closedById String @db.VarChar(19)
firstResponse DateTime? closedReason String?
guild Guild @relation(fields: [guildId], references: [id]) createdBy User @relation(name: "CreatedTickets", fields: [createdById], references: [id])
guildId String @db.VarChar(19) createdById String @db.VarChar(19)
lastMessage DateTime? firstResponse DateTime?
number Int guild Guild @relation(fields: [guildId], references: [id])
open Boolean @default(true) guildId String @db.VarChar(19)
openingMessage String @db.VarChar(19) id String @id @unique @db.VarChar(19)
pinnedMessages Json @default("[]") lastMessage DateTime?
topic String? number Int
open Boolean @default(true)
openingMessage String @db.VarChar(19)
pinnedMessages Json @default("[]")
topic String?
@@unique([guildId, number]) @@unique([guildId, number])
@@map("tickets") @@map("tickets")

View File