-
Notifications
You must be signed in to change notification settings - Fork 1
/
sqlite-setup.sql
51 lines (43 loc) · 1.66 KB
/
sqlite-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
49
50
51
BEGIN;
CREATE TABLE IF NOT EXISTS discord_user(
id INTEGER PRIMARY KEY,
started_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS emoji(
id INTEGER PRIMARY KEY,
fullname VARCHAR(40) NOT NULL,
hash TEXT NOT NULL,
added_by INTEGER NOT NULL REFERENCES discord_user(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS emoji_used(
emoji_id INTEGER NOT NULL REFERENCES emoji(id) ON DELETE CASCADE,
user_id INTEGER NOT NULL REFERENCES discord_user(id) ON DELETE CASCADE,
amount INTEGER DEFAULT 0,
first_used DATETIME DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT emoji_user UNIQUE (emoji_id, user_id)
);
CREATE TABLE IF NOT EXISTS emoji_reacted(
emoji_id INTEGER NOT NULL REFERENCES emoji(id) ON DELETE CASCADE,
user_id INTEGER NOT NULL REFERENCES discord_user(id) ON DELETE CASCADE,
message_id INTEGER NOT NULL,
made_at DATETIME DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT emoji_user_message UNIQUE (emoji_id, user_id, message_id)
);
CREATE TABLE IF NOT EXISTS emoji_favourite(
emoji_id INTEGER NOT NULL REFERENCES emoji(id) ON DELETE CASCADE,
user_id INTEGER NOT NULL REFERENCES discord_user(id) ON DELETE CASCADE,
made_at DATETIME DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT emoji_user_fav UNIQUE (emoji_id, user_id)
);
CREATE TABLE IF NOT EXISTS discord_normal_emojis(
id INTEGER PRIMARY KEY AUTOINCREMENT,
json_data TEXT NOT NULL,
fetched_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS bot_metadata(
id INTEGER PRIMARY KEY AUTOINCREMENT,
data TEXT NOT NULL,
bot_version VARCHAR(10) NOT NULL UNIQUE,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
COMMIT;