-
Notifications
You must be signed in to change notification settings - Fork 0
/
postgres-setup.sql
48 lines (41 loc) · 1.7 KB
/
postgres-setup.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
CREATE TABLE IF NOT EXISTS discord_user(
id BIGINT PRIMARY KEY,
started_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS emoji(
id BIGINT PRIMARY KEY,
fullname VARCHAR(40) NOT NULL,
hash TEXT NOT NULL,
added_by BIGINT NOT NULL REFERENCES discord_user(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS emoji_used(
emoji_id BIGINT NOT NULL REFERENCES emoji(id) ON DELETE CASCADE,
user_id BIGINT NOT NULL REFERENCES discord_user(id) ON DELETE CASCADE,
amount INT DEFAULT 0,
first_used TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT emoji_user UNIQUE (emoji_id, user_id)
);
CREATE TABLE IF NOT EXISTS emoji_reacted(
emoji_id BIGINT NOT NULL REFERENCES emoji(id) ON DELETE CASCADE,
user_id BIGINT NOT NULL REFERENCES discord_user(id) ON DELETE CASCADE,
message_id INT NOT NULL,
made_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT emoji_user_message UNIQUE (emoji_id, user_id, message_id)
);
CREATE TABLE IF NOT EXISTS emoji_favourite(
emoji_id BIGINT NOT NULL REFERENCES emoji(id) ON DELETE CASCADE,
user_id BIGINT NOT NULL REFERENCES discord_user(id) ON DELETE CASCADE,
made_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT emoji_user_fav UNIQUE (emoji_id, user_id)
);
CREATE TABLE IF NOT EXISTS discord_normal_emojis(
id SERIAL PRIMARY KEY,
json_data JSONB NOT NULL,
fetched_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS bot_metadata(
id SERIAL PRIMARY KEY,
data JSONB NOT NULL,
bot_version VARCHAR(10) NOT NULL UNIQUE,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);