Skip to content

Commit 62f74b6

Browse files
authored
Merge pull request #295 from allthingslinux/refactor-multiguild
2 parents 3137677 + 692855e commit 62f74b6

File tree

24 files changed

+532
-1618
lines changed

24 files changed

+532
-1618
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

prisma/schema.prisma

Lines changed: 65 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
datasource db {
22
provider = "postgresql"
3-
url = env("DATABASE_URL")
4-
directUrl = env("DIRECT_URL")
3+
url = env("PROD_DATABASE_URL")
4+
directUrl = env("PROD_DIRECT_URL")
55
}
66

77
generator client {
@@ -13,181 +13,78 @@ generator client {
1313
recursive_type_depth = -1
1414
}
1515

16-
// General settings for the system
17-
model Settings {
18-
// Key of the setting
19-
key String @id
20-
// Value of the setting
21-
value String
22-
// Optional description of what the setting does
23-
description String?
16+
enum CaseType {
17+
BAN
18+
HACK_BAN
19+
TEMP_BAN
20+
UNBAN
21+
KICK
22+
TIMEOUT_ADD
23+
TIMEOUT_REMOVE
24+
WARN
2425
}
2526

26-
model Users {
27-
// The user’s unique ID (via Discord)
28-
id BigInt @id
29-
// The user’s username.
30-
name String
31-
// The user’s global nickname, taking precedence over the username in display.
32-
global_name String?
33-
// Returns the user’s display name. For regular users this is just their global name or their username, but if they have a guild specific nickname then that is returned instead.
34-
display_name String
35-
// Returns a string that allows you to mention the given user.
36-
mention String
37-
// Specifies if the user is a bot account.
38-
bot Boolean @default(false)
39-
// Returns the user’s creation time in UTC. This is when the user’s Discord account was created.
40-
created_at DateTime?
41-
// True if user is a member of a guild (not a discord.py attribute)
42-
is_member Boolean @default(true)
43-
// The guild specific nickname of the user. Takes precedence over the global name.
44-
nick String?
45-
// An aware datetime object that specifies the date and time in UTC that the member joined the guild. If the member left and rejoined the guild, this will be the latest date. In certain cases, this can be None.
46-
joined_at DateTime?
27+
model Guild {
28+
guild_id BigInt @id
29+
guild_joined_at DateTime? @default(now())
30+
cases Case[]
31+
snippets Snippet[]
32+
notes Note[]
33+
reminders Reminder[]
4734
48-
// This is a relation field and is a list of roles that the user has, linking to the `UserRoles` table. If you fetch a user from the database and include this field, you will get all the roles associated with that user.
49-
roles UserRoles[]
50-
51-
// This represents all the infractions that this user has given out when acting as a moderator. It has a `relation` annotation to make clear that for these infractions, this user is referred to in the `moderator` field of the `Infractions` table.
52-
infractions_given Infractions[] @relation("Moderator")
53-
54-
// This is all the infractions that this user has received. It has a `relation` annotation to make clear that for these infractions, this user is referred to in the `user` field of the `Infractions` table.
55-
infractions_received Infractions[] @relation("User")
56-
57-
snippets Snippets[]
58-
59-
afk Boolean @default(false)
60-
afk_reason String?
61-
afk_since DateTime?
62-
63-
notes_given Notes[] @relation("Moderator")
64-
notes_received Notes[] @relation("User")
65-
66-
reminders Reminders[]
67-
CommandStats CommandStats[]
35+
@@unique([guild_id])
6836
}
6937

70-
model Roles {
71-
// The ID for the role (via Discord)
72-
id BigInt @id
73-
// The name of the role
74-
name String
75-
// Indicates if the role will be displayed separately from other members.
76-
hoist Boolean @default(false)
77-
// Indicates if the role is managed by the guild through some form of integrations such as Twitch.
78-
managed Boolean @default(false)
79-
// Indicates if the role is mentionable.
80-
mentionable Boolean @default(false)
81-
// The role’s creation time in UTC.
82-
created_at DateTime?
83-
// Returns a string that allows you to mention a role.
84-
mention String? @default("")
85-
// The role’s color. An integer representation of hexadecimal colour code.
86-
color BigInt?
87-
88-
// This field links a role to the users that have it. It references the `UserRoles` junction table. If you fetch a role from the database and include this field, you will get a list of UserRoles entries and from there you can find all the users that have this role.
89-
users UserRoles[]
90-
91-
// This is a Boolean field indicating if the role is a moderator role. This is not an attribute coming from Discord but an extra field you have defined to distinguish normal roles from moderator roles. It defaults to false, meaning if you don't specify it when creating a new role, it will be assumed to be a non-moderator role.
92-
is_mod Boolean @default(false)
38+
model Case {
39+
case_id BigInt @id @default(autoincrement())
40+
case_type CaseType
41+
case_reason String
42+
case_moderator_id BigInt
43+
case_target_id BigInt
44+
case_number Int?
45+
case_created_at DateTime? @default(now())
46+
case_expires_at DateTime?
47+
guild_id BigInt
48+
guild Guild @relation(fields: [guild_id], references: [guild_id])
49+
50+
@@unique([case_number, guild_id])
51+
@@index([case_number, guild_id])
9352
}
9453

95-
model UserRoles {
96-
user Users @relation(fields: [user_id], references: [id])
97-
user_id BigInt
98-
99-
role Roles @relation(fields: [role_id], references: [id])
100-
role_id BigInt
101-
102-
@@id([user_id, role_id])
54+
model Snippet {
55+
snippet_id BigInt @id @default(autoincrement())
56+
snippet_name String
57+
snippet_content String
58+
snippet_user_id BigInt
59+
snippet_created_at DateTime @default(now())
60+
guild_id BigInt
61+
guild Guild @relation(fields: [guild_id], references: [guild_id])
62+
63+
@@unique([snippet_name, guild_id])
64+
@@index([snippet_name, guild_id])
10365
}
10466

105-
model Infractions {
106-
id BigInt @id @default(autoincrement())
107-
infraction_type String
108-
infraction_reason String?
109-
created_at DateTime? @default(now())
110-
expires_at DateTime?
111-
112-
// These fields establish a relationship with the `Users` model. `moderator_id` is the ID of the user who gave the infraction. The line `moderator Users? @relation("Moderator", fields: [moderator_id], references: [id])` links to the `Users` model, indicating that an instance of `Users` (the moderator) is associated with this infraction.
113-
moderator Users @relation("Moderator", fields: [moderator_id], references: [id])
114-
moderator_id BigInt
115-
116-
// These fields establish another relationship with the `Users` model. `user_id` is the ID of the user who received the infraction. The line `user Users @relation("User", fields: [user_id], references: [id])` links to the `Users` model, indicating that an instance of `Users` (the user who received the infraction) is associated with this infraction.
117-
user Users @relation("User", fields: [user_id], references: [id])
118-
user_id BigInt
67+
model Note {
68+
note_id BigInt @id @default(autoincrement())
69+
note_content String
70+
note_created_at DateTime @default(now())
71+
note_moderator_id BigInt
72+
note_target_id BigInt
73+
note_number Int?
74+
guild_id BigInt
75+
guild Guild @relation(fields: [guild_id], references: [guild_id])
76+
77+
@@unique([note_number, guild_id])
78+
@@index([note_number, guild_id])
11979
}
12080

121-
model Snippets {
122-
// The name of the snippet
123-
name String @id
124-
// The content of the snippet
125-
content String
126-
// The creation time of the snippet
127-
created_at DateTime? @default(now())
128-
129-
// The server ID of the guild where the snippet was created
130-
// 0 is the default value for this field for migration purposes
131-
server_id BigInt @default(0)
132-
133-
// This field establishes a relationship with the `Users` model. `author_id` is the ID of the user who created the snippet. The line `author Users @relation(fields: [author_id], references: [id])` links to the `Users` model, indicating that an instance of `Users` (the author) is associated with this snippet.
134-
author Users @relation(fields: [author_id], references: [id])
135-
author_id BigInt
81+
model Reminder {
82+
reminder_id BigInt @id @default(autoincrement())
83+
reminder_content String
84+
reminder_created_at DateTime @default(now())
85+
reminder_expires_at DateTime
86+
reminder_channel_id BigInt
87+
reminder_user_id BigInt
88+
guild_id BigInt
89+
guild Guild @relation(fields: [guild_id], references: [guild_id])
13690
}
137-
138-
model Notes {
139-
id BigInt @id @default(autoincrement())
140-
content String
141-
created_at DateTime? @default(now())
142-
143-
// These fields establish a relationship with the `Users` model. `moderator_id` is the ID of the user who created the note. The line `moderator Users? @relation("Moderator", fields: [moderator_id], references: [id])` links to the `Users` model, indicating that an instance of `Users` (the moderator) is associated with this note.
144-
moderator Users @relation("Moderator", fields: [moderator_id], references: [id])
145-
moderator_id BigInt
146-
147-
// These fields establish another relationship with the `Users` model. `user_id` is the ID of the user who the note is about. The line `user Users @relation("User", fields: [user_id], references: [id])` links to the `Users` model, indicating that an instance of `Users` (the user who the note is about) is associated with this note.
148-
user Users @relation("User", fields: [user_id], references: [id])
149-
user_id BigInt
150-
}
151-
152-
model Reminders {
153-
id BigInt @id @default(autoincrement())
154-
content String
155-
created_at DateTime? @default(now())
156-
expires_at DateTime
157-
channel_id BigInt
158-
guild_id BigInt
159-
160-
// These fields establish a relationship with the `Users` model. `author_id` is the ID of the user who created the reminder. The line `author Users @relation(fields: [author_id], references: [id])` links to the `Users` model, indicating that an instance of `Users` (the author) is associated with this reminder.
161-
user Users @relation(fields: [user_id], references: [id])
162-
user_id BigInt
163-
}
164-
165-
model Commands {
166-
id BigInt @id @default(autoincrement())
167-
name String
168-
content String
169-
created_at DateTime? @default(now())
170-
CommandStats CommandStats[]
171-
}
172-
173-
model CommandStats {
174-
id BigInt @id @default(autoincrement())
175-
command_id BigInt
176-
user_id BigInt
177-
used_at DateTime? @default(now())
178-
179-
command Commands @relation(fields: [command_id], references: [id])
180-
user Users @relation(fields: [user_id], references: [id])
181-
}
182-
183-
model EmojiStats {
184-
emoji_id BigInt @id
185-
count BigInt
186-
}
187-
188-
// model Logs {
189-
// id BigInt @id
190-
// content String
191-
// log_type String
192-
// created_at DateTime @default(now())
193-
// }

0 commit comments

Comments
 (0)