-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathschema.sql
102 lines (89 loc) · 3.2 KB
/
schema.sql
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
-- Created for PostgreSQL 10
DROP TABLE IF EXISTS guild_attachments, private_attachments, guild_edits, private_edits, guild_deletions,
private_deletions, guild_messages, private_messages, guild_channels, private_channels, guilds, users;
CREATE TABLE users
(
user_id BIGINT PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
name TEXT NOT NULL,
discriminator VARCHAR(4) NOT NULL,
is_bot BOOLEAN NOT NULL,
last_updated TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE guilds
(
guild_id BIGINT PRIMARY KEY,
name TEXT NOT NULL,
last_updated TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE guild_channels
(
channel_id BIGINT PRIMARY KEY,
guild_id BIGINT NOT NULL REFERENCES guilds (guild_id),
name TEXT NOT NULL,
last_updated TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE private_channels
(
channel_id BIGINT PRIMARY KEY,
user_id1 BIGINT NOT NULL REFERENCES users (user_id),
user_id2 BIGINT NOT NULL REFERENCES users (user_id)
);
CREATE TABLE guild_messages
(
message_id BIGINT PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
channel_id BIGINT NOT NULL REFERENCES guild_channels (channel_id),
user_id BIGINT NOT NULL REFERENCES users (user_id),
content TEXT NOT NULL,
rich_embed JSON
);
CREATE TABLE private_messages
(
message_id BIGINT PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
channel_id BIGINT NOT NULL REFERENCES private_channels (channel_id),
user_id BIGINT NOT NULL REFERENCES users (user_id),
content TEXT NOT NULL,
rich_embed JSON
);
CREATE TABLE guild_edits
(
message_id BIGINT NOT NULL REFERENCES guild_messages (message_id),
edited_at TIMESTAMP WITH TIME ZONE NOT NULL,
content TEXT NOT NULL,
embed JSON
);
CREATE TABLE private_edits
(
message_id BIGINT NOT NULL REFERENCES private_messages (message_id),
edited_at TIMESTAMP WITH TIME ZONE NOT NULL,
content TEXT NOT NULL,
embed JSON
);
CREATE TABLE guild_deletions
(
message_id BIGINT NOT NULL REFERENCES guild_messages (message_id),
deleted_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE private_deletions
(
message_id BIGINT NOT NULL REFERENCES private_messages (message_id),
deleted_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE guild_attachments
(
attachment_id BIGINT PRIMARY KEY,
message_id BIGINT NOT NULL REFERENCES guild_messages (message_id),
filesize INTEGER NOT NULL,
filename TEXT NOT NULL,
url TEXT NOT NULL
);
CREATE TABLE private_attachments
(
attachment_id BIGINT PRIMARY KEY,
message_id BIGINT NOT NULL REFERENCES private_messages (message_id),
filesize INTEGER NOT NULL,
filename TEXT NOT NULL,
url TEXT NOT NULL
);