-
Notifications
You must be signed in to change notification settings - Fork 6
/
schema.sql
120 lines (105 loc) · 3.07 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
-- noinspection SpellCheckingInspectionForFile
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE TABLE IF NOT EXISTS timers (
id BIGSERIAL PRIMARY KEY,
precise BOOLEAN DEFAULT TRUE,
event TEXT,
extra JSONB,
created TIMESTAMP,
expires TIMESTAMP
);
CREATE TABLE IF NOT EXISTS blocks (
guild_id BIGINT,
channel_id BIGINT,
user_id BIGINT,
PRIMARY KEY (guild_id, channel_id, user_id)
);
CREATE TABLE IF NOT EXISTS addbot (
owner_id bigint NOT NULL,
bot_id bigint NOT NULL UNIQUE,
added boolean DEFAULT false NOT NULL,
pending boolean DEFAULT true NOT NULL,
reason text,
PRIMARY KEY (owner_id, bot_id)
);
-- Thanks chai :) and Laggy
DO $$
BEGIN
CREATE TYPE blacklist_type AS ENUM ('guild', 'channel', 'user');
EXCEPTION
WHEN duplicate_object THEN null;
END$$;
CREATE TABLE IF NOT EXISTS blacklist (
blacklist_type blacklist_type,
entity_id bigint,
guild_id bigint NOT NULL default 0,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
reason TEXT,
PRIMARY KEY (blacklist_type, entity_id, guild_id)
);
-- For tags.
CREATE TABLE IF NOT EXISTS tags (
id BIGSERIAL,
name VARCHAR(200),
content VARCHAR(2000),
owner_id BIGINT,
guild_id BIGINT,
uses INT DEFAULT 0,
created_at TIMESTAMP WITH TIME ZONE
NOT NULL DEFAULT NOW(),
points_to BIGINT
REFERENCES tags(id)
ON DELETE CASCADE,
embed JSONB,
PRIMARY KEY (id),
UNIQUE (name, guild_id),
CONSTRAINT tags_mutually_excl_cnt_p_to CHECK (
((content IS NOT NULL OR embed IS NOT NULL) and points_to IS NULL)
OR (points_to IS NOT NULL and (content IS NULL AND embed IS NULL))
)
);
CREATE INDEX IF NOT EXISTS tags_name_ind ON tags (name);
CREATE INDEX IF NOT EXISTS tags_location_id_ind ON tags (guild_id);
-- noinspection SqlResolve
CREATE INDEX IF NOT EXISTS tags_name_trgm_ind ON tags USING GIN (name gin_trgm_ops);
CREATE INDEX IF NOT EXISTS tags_name_lower_ind ON tags (LOWER(name));
CREATE UNIQUE INDEX IF NOT EXISTS tags_uniq_ind ON tags (LOWER(name), guild_id);
CREATE TABLE commands (
user_id BIGINT NOT NULL,
guild_id BIGINT,
command TEXT NOT NULL ,
timestamp TIMESTAMP WITH TIME ZONE
NOT NULL DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS message_info (
author_id BIGINT,
message_id BIGINT,
channel_id BIGINT,
embed_count INT,
attachment_count INT,
created_at TIMESTAMP WITH TIME ZONE,
edited_at TIMESTAMP WITH TIME ZONE,
deleted BOOLEAN DEFAULT FALSE,
is_bot BOOLEAN DEFAULT FALSE,
PRIMARY KEY (message_id, channel_id)
);
CREATE TABLE IF NOT EXISTS status_history(
user_id BIGINT,
status TEXT,
changed_at TIMESTAMP WITH TIME ZONE
);
DO $$
BEGIN
CREATE TYPE archive_mode AS ENUM ('leave', 'inactive', 'manual');
EXCEPTION
WHEN duplicate_object THEN null;
END$$;
CREATE TABLE IF NOT EXISTS pits (
pit_id BIGINT UNIQUE,
pit_owner BIGINT UNIQUE,
archive_mode archive_mode
);
CREATE TABLE IF NOT EXISTS user_settings(
user_id BIGINT PRIMARY KEY,
timezone TEXT
);