-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema_v1.sql
More file actions
198 lines (142 loc) · 6.39 KB
/
schema_v1.sql
File metadata and controls
198 lines (142 loc) · 6.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
-- -- -- -- -- --
-- GUILD: ID, OWNER_ID, _NAME
-- USER: ID, _NAME
-- -- -- -- -- --
CREATE TABLE IF NOT EXISTS guilds (
id bigint unsigned NOT NULL,
owner_id bigint unsigned NOT NULL,
_name text NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS users (
id bigint unsigned NOT NULL,
_name varchar(255) NOT NULL,
discrim varchar(6) NOT NULL, -- Limit discrims for 6 digits, if we reach limits with this; theres a problem above concerns of just adding more numbers to it, it will kinda serve as a reminder to implement some kinda friend code system.
authentication TEXT NOT NULL,
salt TEXT NOT NULL,
created_at bigint unsigned NOT NULL DEFAULT UNIX_TIMESTAMP(),
-- TODO: discriminator
PRIMARY KEY (id, discrim)
);
-- -- -- -- -- --
-- CHANNELS: GUILD_ID, ID, _NAME
-- MESSAGES: ID, DMCHANNELID, CHANNELID, CONTENT, SENT_TIMESTAMP
-- DMCHANNELS: ID
-- DMCHANNELUSERS: PARENT_ID, USER_ID
-- GUILDUSERS: PARENT_ID, USER_ID
-- -- -- -- -- --
CREATE TABLE IF NOT EXISTS channels (
guild_id bigint unsigned,
old_guild_id bigint unsigned,
id bigint unsigned NOT NULL,
_name text NOT NULL,
delete_after_timestamp bigint unsigned,
PRIMARY KEY (id),
FOREIGN KEY (guild_id) REFERENCES guilds(id),
CHECK (ISNULL(guild_id) + ISNULL(old_guild_id) = 1), -- A channel is either attached or detached from a guild
CONSTRAINT permadelete CHECK (ISNULL(old_guild_id) + ISNULL(delete_after_timestamp) IN (0, 2)) -- If a channel is detached, it must have a set deletion time
);
CREATE TABLE DMs (
id bigint unsigned NOT NULL,
UserOneID bigint unsigned, -- If any of the user IDs are null, then the account has been deleted.
UserTwoID bigint unsigned,
FOREIGN KEY (UserOneID) REFERENCES users(id) ON DELETE SET NULL,
FOREIGN KEY (UserTwoID) REFERENCES users(id) ON DELETE SET NULL,
PRIMARY KEY (id)
);
CREATE TABLE DMChannels (
id bigint unsigned NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE DMchannelUsers (
parent_id bigint unsigned NOT NULL, -- This would be the DM Channel's ID
user_id bigint unsigned NOT NULL,
PRIMARY KEY (parent_id, user_id),
FOREIGN KEY (parent_id) REFERENCES DMChannels(id),
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
CREATE TABLE guildUsers (
parent_id bigint unsigned NOT NULL, -- This would be the guild's ID
user_id bigint unsigned NOT NULL,
PRIMARY KEY (parent_id, user_id),
FOREIGN KEY (parent_id) REFERENCES guilds(id),
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
CREATE TABLE DMmessages ( -- This table is for DM messages
id bigint unsigned NOT NULL,
authorID bigint unsigned,
DmID bigint unsigned,
content text NOT NULL,
sent_timestamp bigint unsigned NOT NULL DEFAULT UNIX_TIMESTAMP(),
PRIMARY KEY (id),
FOREIGN KEY (DmID) REFERENCES DMs(id),
FOREIGN KEY (authorID) REFERENCES users(id) ON DELETE SET NULL -- Author
);
CREATE TABLE DMChannelmessages ( -- This table is for DMChannel messages
id bigint unsigned NOT NULL,
authorID bigint unsigned,
DMChannelID bigint unsigned NOT NULL, -- This, unlike author IDs, cannot be null; if the channel is deleted then CASCADE
content text NOT NULL,
sent_timestamp bigint unsigned NOT NULL DEFAULT UNIX_TIMESTAMP(),
PRIMARY KEY (id),
FOREIGN KEY (DMChannelID) REFERENCES DMChannels(id) ON DELETE CASCADE, -- Channel
FOREIGN KEY (authorID) REFERENCES users(id) ON DELETE SET NULL -- Author
);
CREATE TABLE messages (
id bigint unsigned NOT NULL,
authorID bigint unsigned,
channelID bigint unsigned NOT NULL, -- Channel
content text NOT NULL,
sent_timestamp bigint unsigned NOT NULL DEFAULT UNIX_TIMESTAMP(),
PRIMARY KEY (id),
FOREIGN KEY (channelID) REFERENCES channels(id) ON DELETE CASCADE, -- Channel
FOREIGN KEY (authorID) REFERENCES users(id) ON DELETE SET NULL -- Author
);
-- -- -- -- -- -- Special clarification is needed for all of this, even if only for myself.
CREATE TABLE rolePermissions ( -- On creation of every role, this table should be populated with data, this data is for GUILD WIDE PERMS only.
-- On creation of the GUILD, this table should be ppopulated with the DEFAULT permissions for a DEFAULT role.
guildID bigint unsigned, -- The guild .
roleID bigint unsigned, -- The role thats getting permissions.
-- Default permissions
send_message boolean not null default 1, -- A user can send messages by default.
view_channels boolean not null default 1, -- A user can see open channels by default.
-- Specific permissions
delete_message boolean not null default 0, -- Only Authorized users should be able to delete other user messages.
change_nick boolean not null default 0, -- Only Authorized users should be able to change other user nicknames.
manage_guild boolean not null default 0, -- Only Authorized users should be able to change guild settings.
manage_roles boolean not null default 0, -- Only Authorized users should be able to change role settings.
kick_perms boolean not null default 0, -- Only Authorized users should be able to kick.
ban_perms boolean not null default 0, -- Only Authorized users should be able to kick.
PRIMARY KEY (guildID, roleID),
FOREIGN KEY (guildID) REFERENCES guilds(id) ON DELETE CASCADE, -- Guild deleted, set the guild to NULL
);
-- -- -- -- -- --
-- -- -- -- -- --
-- ROLES: GUILD_ID, ID, _NAME
-- PENDINGFRIENDREQUESTS: ID, DMCHANNELID, CHANNELID, CONTENT, SENT_TIMESTAMP
-- FRIENDS: ID
-- -- -- -- -- --
CREATE TABLE roles (
guildID bigint unsigned,
id bigint unsigned NOT NULL,
_name text NOT NULL,
PRIMARY KEY (guildID, id),
FOREIGN KEY (parent_id) REFERENCES DMChannels(id),
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
CREATE TABLE pendingFriendRequests (
outgoingUserID bigint unsigned NOT NULL,
incomingUserID bigint unsigned NOT NULL,
start_timestamp bigint unsigned NOT NULL DEFAULT UNIX_TIMESTAMP(),
PRIMARY KEY (outgoingUserID, incomingUserID),
FOREIGN KEY (outgoingUserID) REFERENCES users(id),
FOREIGN KEY (incomingUserID) REFERENCES users(id)
);
CREATE TABLE friends (
userOneID bigint unsigned NOT NULL,
userTwoID bigint unsigned NOT NULL,
start_timestamp bigint unsigned NOT NULL DEFAULT UNIX_TIMESTAMP(),
PRIMARY KEY (userOneID, userTwoID),
FOREIGN KEY (userOneID) REFERENCES users(id),
FOREIGN KEY (userTwoID) REFERENCES users(id)
);