forked from ViStefan/ngk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.sql
99 lines (87 loc) · 3.29 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
create table if not exists sync_states(
post_id integer primary key,
last_comment_id integer,
pending boolean,
priority integer,
synced timestamp,
result varchar
);
create table if not exists users(
user_id integer primary key,
name varchar,
avatar_hash varchar,
source INTEGER
);
create table if not exists posts(
post_id integer primary key,
comment_list_id integer,
user_id integer,
language varchar,
code varchar,
text varchar,
text_tsv tsvector,
posted timestamp,
vote_plus integer,
vote_minus integer,
rating numeric,
source INTEGER
);
create table if not exists comments(
comment_id integer primary key,
comment_id_xyz INTEGER, -- Deprecated
post_id integer,
parent_id integer,
user_id integer,
text varchar,
text_tsv tsvector,
posted timestamp,
vote_plus integer,
vote_minus integer,
rating numeric,
source INTEGER
);
CREATE TABLE IF NOT EXISTS comment_ids_storage(
comment_id_ru INTEGER PRIMARY KEY,
comment_id_xyz INTEGER
);
CREATE TABLE IF NOT EXISTS user_settings(
id VARCHAR PRIMARY KEY,
ignored_users INTEGER[],
ignored_posts INTEGER[],
custom_filter VARCHAR
);
CREATE TABLE IF NOT EXISTS moderators(
id VARCHAR NOT NULL PRIMARY KEY,
pubkey VARCHAR NOT NULL
);
CREATE TABLE IF NOT EXISTS auto_moderators(
id VARCHAR NOT NULL PRIMARY KEY,
secret VARCHAR NOT NULL,
update_url VARCHAR NOT NULL,
FOREIGN KEY(id) REFERENCES moderators(id)
);
CREATE TABLE IF NOT EXISTS banned_users(
user_id INTEGER NOT NULL,
moderator_id VARCHAR NOT NULL,
ban_date TIMESTAMPTZ NOT NULL,
PRIMARY KEY(user_id, moderator_id),
FOREIGN KEY(moderator_id) REFERENCES moderators(id)
);
CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE OF text ON comments FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger(text_tsv, 'pg_catalog.russian', text);
CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE OF text ON posts FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger(text_tsv, 'pg_catalog.russian', text);
create index if not exists comments_posted on comments(posted);
CREATE INDEX IF NOT EXISTS weighted_tsv_idx_comments ON comments USING GIST (text_tsv);
CREATE INDEX IF NOT EXISTS weighted_tsv_idx_posts ON posts USING GIST (text_tsv);
CREATE INDEX IF NOT EXISTS comments_text_trgm ON comments USING GIN (text gin_trgm_ops);
CREATE INDEX IF NOT EXISTS user_names ON users(lower(name));
CREATE INDEX IF NOT EXISTS user_name_prefixes ON users(lower(name) text_pattern_ops);
CREATE INDEX IF NOT EXISTS comments_user_ids ON comments(user_id);
CREATE INDEX IF NOT EXISTS posts_user_ids ON posts(user_id);
CREATE INDEX IF NOT EXISTS comments_comment_ids ON comments(comment_id);
CREATE INDEX IF NOT EXISTS posts_post_ids ON posts(post_id);
CREATE INDEX IF NOT EXISTS users_user_ids ON users(user_id);
CREATE INDEX IF NOT EXISTS comment_ids_storage_ids_ru_xyz ON comment_ids_storage(comment_id_ru, comment_id_xyz);
CREATE INDEX IF NOT EXISTS comment_ids_storage_ids_xyz_ru ON comment_ids_storage(comment_id_xyz, comment_id_ru);
CREATE INDEX IF NOT EXISTS user_settings_ids ON user_settings(id);
CREATE INDEX IF NOT EXISTS idx$moderators_pubkey ON moderators(pubkey);
CREATE INDEX IF NOT EXISTS idx$banned_users_ban_date ON banned_users(ban_date);