-
Notifications
You must be signed in to change notification settings - Fork 1
/
schema.sql
199 lines (170 loc) · 4.96 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
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
199
CREATE EXTENSION IF NOT EXISTS citext;
CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE TABLE IF NOT EXISTS blacklist (
user_id BIGINT UNIQUE NOT NULL,
reason TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS whitelist (
guild_id BIGINT UNIQUE NOT NULL,
user_id BIGINT NOT NULL,
receipt_id TEXT NOT NULL,
PRIMARY KEY (user_id, receipt_id)
);
CREATE TABLE IF NOT EXISTS settings (
guild_id BIGINT UNIQUE NOT NULL,
prefix TEXT,
mod_log_channel_id BIGINT,
backup_task BOOLEAN NOT NULL DEFAULT FALSE
);
CREATE TABLE IF NOT EXISTS cases (
id BIGINT NOT NULL,
guild_id BIGINT NOT NULL,
target_id BIGINT NOT NULL,
moderator_id BIGINT NOT NULL,
message_id BIGINT,
reason TEXT NOT NULL DEFAULT 'No reason provided',
"action" BIGINT NOT NULL DEFAULT 0,
action_expiration TIMESTAMP WITH TIME ZONE,
action_processed BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE,
PRIMARY KEY (id, guild_id)
);
-- CREATE TABLE IF NOT EXISTS backups (
-- backup_id TEXT NOT NULL,
-- guild_id BIGINT NOT NULL,
-- created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
-- "image" JSONB NOT NULL,
-- PRIMARY KEY (backup_id, guild_id)
-- );
CREATE TABLE IF NOT EXISTS welcome_messages (
guild_id BIGINT NOT NULL,
channel_id BIGINT NOT NULL,
template TEXT NOT NULL,
PRIMARY KEY (guild_id, channel_id)
);
CREATE TABLE IF NOT EXISTS goodbye_messages (
guild_id BIGINT NOT NULL,
channel_id BIGINT NOT NULL,
template TEXT NOT NULL,
PRIMARY KEY (guild_id, channel_id)
);
CREATE TABLE IF NOT EXISTS boost_messages (
guild_id BIGINT NOT NULL,
channel_id BIGINT NOT NULL,
template TEXT NOT NULL,
PRIMARY KEY (guild_id, channel_id)
);
CREATE SCHEMA IF NOT EXISTS feeds;
CREATE TABLE IF NOT EXISTS feeds.instagram (
username TEXT NOT NULL,
user_id BIGINT NOT NULL,
guild_id BIGINT NOT NULL,
channel_id BIGINT NOT NULL,
posts JSONB[] NOT NULL DEFAULT ARRAY[]::JSONB[],
PRIMARY KEY (user_id, guild_id)
);
CREATE SCHEMA IF NOT EXISTS highlight;
CREATE TABLE IF NOT EXISTS highlight.words (
guild_id BIGINT NOT NULL,
user_id BIGINT NOT NULL,
keyword CITEXT NOT NULL,
PRIMARY KEY (guild_id, user_id, keyword)
);
CREATE TABLE IF NOT EXISTS highlight.blacklist (
user_id BIGINT NOT NULL,
entity_id BIGINT NOT NULL,
PRIMARY KEY (user_id, entity_id)
);
CREATE SCHEMA IF NOT EXISTS metrics;
CREATE TABLE IF NOT EXISTS metrics.names (
user_id BIGINT NOT NULL,
name TEXT NOT NULL,
pomelo BOOLEAN DEFAULT TRUE,
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS metrics.avatars (
user_id BIGINT NOT NULL,
asset TEXT NOT NULL,
key TEXT NOT NULL,
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
PRIMARY KEY (user_id, key)
);
CREATE SCHEMA IF NOT EXISTS lastfm;
CREATE TABLE IF NOT EXISTS lastfm.config (
user_id BIGINT UNIQUE NOT NULL,
username TEXT NOT NULL,
color BIGINT,
reactions JSONB[] NOT NULL DEFAULT ARRAY[]::JSONB[]
);
CREATE TABLE IF NOT EXISTS lastfm.commands (
user_id BIGINT NOT NULL,
command TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS lastfm.artists (
user_id BIGINT NOT NULL,
username TEXT NOT NULL,
artist CITEXT NOT NULL,
plays BIGINT NOT NULL,
PRIMARY KEY (user_id, artist)
);
CREATE TABLE IF NOT EXISTS lastfm.albums (
user_id BIGINT NOT NULL,
username TEXT NOT NULL,
artist CITEXT NOT NULL,
album CITEXT NOT NULL,
plays BIGINT NOT NULL,
PRIMARY KEY (user_id, artist, album)
);
CREATE TABLE IF NOT EXISTS lastfm.tracks (
user_id BIGINT NOT NULL,
username TEXT NOT NULL,
artist CITEXT NOT NULL,
track CITEXT NOT NULL,
plays BIGINT NOT NULL,
PRIMARY KEY (user_id, artist, track)
);
CREATE TABLE IF NOT EXISTS lastfm.crowns (
guild_id BIGINT NOT NULL,
user_id BIGINT NOT NULL,
username TEXT NOT NULL,
artist CITEXT NOT NULL,
plays BIGINT NOT NULL,
PRIMARY KEY (guild_id, artist)
);
CREATE OR REPLACE FUNCTION NEXT_CASE(BIGINT) RETURNS BIGINT
LANGUAGE plpgsql
AS $$
DECLARE
next_id BIGINT;
BEGIN
SELECT MAX(id) INTO next_id FROM cases WHERE guild_id = $1;
IF next_id IS NULL THEN RETURN 1; END IF;
RETURN next_id + 1;
END;
$$;
-- CREATE OR REPLACE FUNCTION limit_backups()
-- RETURNS TRIGGER AS $$
-- DECLARE
-- backup_count INTEGER;
-- BEGIN
-- SELECT COUNT(*) INTO backup_count
-- FROM backups
-- WHERE guild_id = NEW.guild_id;
-- IF backup_count > 10 THEN
-- DELETE FROM backups
-- WHERE (backup_id, guild_id) IN (
-- SELECT backup_id, guild_id
-- FROM backups
-- WHERE guild_id = NEW.guild_id
-- ORDER BY created_at ASC
-- LIMIT 1
-- );
-- END IF;
-- RETURN NEW;
-- END;
-- $$ LANGUAGE plpgsql;
-- CREATE OR REPLACE TRIGGER limit_backups_trigger
-- BEFORE INSERT ON backups
-- FOR EACH ROW
-- EXECUTE FUNCTION limit_backups();