You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(schema.prisma): switch database provider from sqlite to postgresql for better scalability and performance
chore(schema.prisma): comment out old postgresql datasource configuration for future reference
refactor(schema.prisma): update database schema to better represent Discord data
- Replace 'roles' model with 'Users' and 'Roles' models to separate user and role data
- Add 'UserRoles' model to represent many-to-many relationship between users and roles
- Replace 'notes' model with 'Infractions' and 'Snippets' models to separate infraction and snippet data
- Remove 'moderators', 'settings', 'logs', 'guilds', and 'messages' models as they are not needed in the new schema
- Add 'InfractionType' enum to represent different types of infractions
- Update comments to better explain the purpose of each model and field
These changes were made to better align the database schema with the data provided by Discord and to simplify the data model.
feat: add new models for logs, user_roles, notes, snippets, guilds, infractions to extend database schema
WHY: To support new features such as logging, user roles, moderator notes, text snippets, guilds, and user infractions.
// The user’s global nickname, taking precedence over the username in display.
28
+
global_nameString?
29
+
// 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.
30
+
display_nameString
31
+
// Returns a string that allows you to mention the given user.
32
+
mentionString
33
+
// Specifies if the user is a bot account.
34
+
botBoolean
35
+
// Returns the user’s creation time in UTC. This is when the user’s Discord account was created.
36
+
created_atDateTime
37
+
// True if user is a member of a guild (not a discord.py attribute)
38
+
is_memberBoolean@default(true)
39
+
// The guild specific nickname of the user. Takes precedence over the global name.
40
+
nickString?
41
+
// 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.
42
+
joined_atDateTime?
33
43
34
-
// General settings for the system
35
-
modelsettings {
36
-
// Key of the setting
37
-
setting_keyString@id
38
-
// Value of the setting
39
-
setting_valueString
40
-
// Optional description of what the setting does
41
-
setting_descriptionString?
42
-
}
44
+
// 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.
45
+
rolesUserRoles[]
43
46
44
-
// Table representing users in the system
45
-
modelusers {
46
-
// User identifier (Discord ID)
47
-
user_idBigInt@id
48
-
// Indicator if the user is a bot
49
-
user_is_botBoolean?
50
-
// Optional User's username
51
-
user_usernameString?
52
-
// Optional User's global name
53
-
user_global_nameString?
54
-
// Timestamp when user was created
55
-
user_created_atDateTime
56
-
// Link to roles associated with this user
57
-
user_rolesuser_roles[]
58
-
// Link to notes associated with this user
59
-
notesnotes[]
60
-
// Link to infractions associated with this user
61
-
infractionsinfractions[]
62
-
}
47
+
// 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.
// 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.
// Indicates if the role will be displayed separately from other members.
62
+
hoistBoolean
63
+
// Indicates if the role is managed by the guild through some form of integrations such as Twitch.
64
+
managedBoolean@default(false)
65
+
// Indicates if the role is mentionable.
66
+
mentionableBoolean@default(false)
67
+
// The role’s creation time in UTC.
68
+
created_atDateTime
69
+
// Returns a string that allows you to mention a role.
70
+
mentionString@default("")
71
+
72
+
// 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.
73
+
usersUserRoles[]
74
+
75
+
// 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.
76
+
is_modBoolean@default(false)
88
77
}
89
78
90
-
// Relationship table between a user and their roles
91
-
modeluser_roles {
92
-
// User identifier
79
+
modelUserRoles {
80
+
idBigInt@id@default(autoincrement())
81
+
82
+
// These refer to the `Users` model. `user_id` is the ID of a user from the `Users` table. The line `user Users @relation(fields: [user_id], references: [id])` implies that `user` establishes a relation with `Users` model based on the `user_id` in this `UserRoles` model and the `id` in the `Users` model.
// These refer to the `Roles` model. `role_id` is the ID of a role from the `Roles` table. The line `role Roles @relation(fields: [role_id], references: [id])` implies that `role` establishes a relation with `Roles` model based on the `role_id` in this `UserRoles` model and the `id` in the `Roles` model.
// Composite primary key consisting of user_id and role_id
102
-
@@id([user_id, role_id])
90
+
// This specifies a composite unique constraint on `user_id` and `role_id`, meaning each combination of a user id and role id must be unique. It prevents a single user from having the same role multiple times. This constraint helps to maintain data integrity.
91
+
@@unique([user_id, role_id])
103
92
}
104
93
105
-
// Table for storing notes/moderator reports on users
// Table representing guilds/servers in the system
132
-
modelguilds {
133
-
// Unique identifier for the guild (Discord ID)
134
-
guild_idBigInt@id
135
-
// Name of the guild
136
-
guild_nameString
137
-
// ID of the owner of the guild
138
-
guild_owner_idBigInt
139
-
}
108
+
// 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.
// 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.
0 commit comments