-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudyHelperBotDB.sql
383 lines (334 loc) · 11.2 KB
/
StudyHelperBotDB.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
CREATE SEQUENCE log_homeworks_homework_id_seq1;
CREATE TABLE permissions
(
permission_id integer GENERATED ALWAYS AS IDENTITY
CONSTRAINT permissions_pk
PRIMARY KEY,
permission_description text,
talk_with_bot boolean DEFAULT TRUE NOT NULL,
list_lectures boolean DEFAULT FALSE NOT NULL,
list_exams boolean DEFAULT FALSE NOT NULL,
list_stats boolean DEFAULT FALSE NOT NULL,
add_lectures boolean DEFAULT FALSE NOT NULL,
add_exams boolean DEFAULT FALSE NOT NULL,
accept_lectures boolean DEFAULT FALSE NOT NULL,
accept_exams boolean DEFAULT FALSE NOT NULL,
manage_lectures boolean DEFAULT FALSE NOT NULL,
manage_exams boolean DEFAULT FALSE NOT NULL,
course_sync boolean DEFAULT FALSE NOT NULL,
list_users boolean DEFAULT FALSE NOT NULL,
add_users boolean DEFAULT FALSE NOT NULL,
remove_users boolean DEFAULT FALSE NOT NULL,
manage_permissions boolean DEFAULT FALSE NOT NULL,
list_server_status boolean DEFAULT FALSE NOT NULL,
list_logs boolean DEFAULT FALSE NOT NULL
);
CREATE UNIQUE INDEX permissions_permission_id_uindex
ON permissions (permission_id);
CREATE TABLE chats
(
tg_chat_id bigint NOT NULL
CONSTRAINT chats_pk
PRIMARY KEY,
chat_type text NOT NULL
);
CREATE UNIQUE INDEX chats_tg_chat_id_uindex
ON chats (tg_chat_id);
CREATE TABLE users
(
tg_user_id bigint NOT NULL
CONSTRAINT users_pk
PRIMARY KEY,
tg_chat_id bigint NOT NULL
CONSTRAINT users_tg_chat_id_fk
REFERENCES chats
ON DELETE RESTRICT,
usos_id integer,
joined_timestamp timestamp WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
first_name text,
last_name text,
verified boolean DEFAULT FALSE NOT NULL,
permission integer NOT NULL
CONSTRAINT users_permission_fk
REFERENCES permissions
ON DELETE RESTRICT
);
CREATE UNIQUE INDEX users_usos_id_uindex
ON users (usos_id);
CREATE UNIQUE INDEX users_tg_user_id_uindex
ON users (tg_user_id);
CREATE UNIQUE INDEX users_tg_chat_id_uindex
ON users (tg_chat_id);
CREATE TABLE group_types
(
group_type_id text NOT NULL
CONSTRAINT group_types_pk
PRIMARY KEY,
group_type_name text,
max_group_size integer
);
CREATE UNIQUE INDEX group_types_group_type_id_uindex
ON group_types (group_type_id);
CREATE TABLE terms
(
usos_term_id text NOT NULL
CONSTRAINT terms_pk
PRIMARY KEY,
term_name text,
start_date date NOT NULL,
end_date date NOT NULL
);
CREATE UNIQUE INDEX terms_usos_term_id_uindex
ON terms (usos_term_id);
CREATE TABLE courses
(
course_id text NOT NULL
CONSTRAINT courses_pk
PRIMARY KEY,
course_name text NOT NULL,
term_id text NOT NULL
CONSTRAINT courses_term_id_fk
REFERENCES terms
ON DELETE RESTRICT
);
CREATE UNIQUE INDEX courses_course_id_uindex
ON courses (course_id);
CREATE TABLE rooms
(
room_id text NOT NULL
CONSTRAINT rooms_pk
PRIMARY KEY,
capacity integer DEFAULT 0
);
COMMENT ON TABLE rooms IS 'Info about rooms';
CREATE UNIQUE INDEX rooms_room_id_uindex
ON rooms (room_id);
CREATE TABLE teachers
(
teacher_usos_id integer NOT NULL
CONSTRAINT teachers_pk
PRIMARY KEY,
first_name text NOT NULL,
last_name text NOT NULL,
email text,
title text,
private_room text
CONSTRAINT teachers_private_room_fk
REFERENCES rooms
ON DELETE RESTRICT
);
CREATE UNIQUE INDEX teachers_usos_id_uindex
ON teachers (teacher_usos_id);
CREATE TABLE study_programmes
(
programme_id text NOT NULL
CONSTRAINT study_programmes_pk
PRIMARY KEY,
programme_name text
);
CREATE UNIQUE INDEX study_programmes_id_uindex
ON study_programmes (programme_id);
CREATE TABLE user_programme
(
user_id bigint NOT NULL
CONSTRAINT user_fk
REFERENCES users
ON DELETE RESTRICT,
programme_id text NOT NULL
CONSTRAINT programme_fk
REFERENCES study_programmes
ON DELETE RESTRICT
);
CREATE UNIQUE INDEX user_programme_uindex
ON user_programme (user_id, programme_id);
CREATE TABLE usos_units
(
usos_unit_id integer NOT NULL
CONSTRAINT usos_units_pk
PRIMARY KEY,
course text NOT NULL
CONSTRAINT usos_units_course_fk
REFERENCES courses
ON DELETE RESTRICT
);
CREATE UNIQUE INDEX usos_units_usos_unit_id_uindex
ON usos_units (usos_unit_id);
CREATE TABLE unit_groups
(
unit_group_id integer GENERATED ALWAYS AS IDENTITY
CONSTRAINT course_groups_pk
PRIMARY KEY,
usos_unit_id integer NOT NULL
CONSTRAINT unit_groups_course_fk
REFERENCES usos_units
ON DELETE RESTRICT,
group_number integer NOT NULL,
group_type text NOT NULL
CONSTRAINT unit_groups_group_type_fk
REFERENCES group_types
ON DELETE RESTRICT
);
COMMENT ON TABLE unit_groups IS 'Groups per each course unit';
CREATE UNIQUE INDEX unit_id_group_number_uindex
ON unit_groups (usos_unit_id, group_number);
CREATE TABLE group_teacher
(
unit_group integer NOT NULL
CONSTRAINT group_fk
REFERENCES unit_groups
ON DELETE RESTRICT,
teacher integer NOT NULL
CONSTRAINT teacher_fk
REFERENCES teachers
ON DELETE RESTRICT
);
CREATE UNIQUE INDEX group_teacher_uindex
ON group_teacher (unit_group, teacher);
CREATE TABLE activities
(
activity_id integer GENERATED ALWAYS AS IDENTITY
CONSTRAINT activities_pk
PRIMARY KEY,
start_time timestamp WITH TIME ZONE NOT NULL,
end_time timestamp WITH TIME ZONE NOT NULL,
room text NOT NULL
CONSTRAINT activities_room_fk
REFERENCES rooms
ON DELETE RESTRICT,
unit_group integer NOT NULL
CONSTRAINT activities_unit_group_fk
REFERENCES unit_groups
ON DELETE RESTRICT
);
CREATE UNIQUE INDEX activities_activity_id_uindex
ON activities (activity_id);
CREATE UNIQUE INDEX activities_group_collision_uindex
ON activities (unit_group, start_time, end_time);
CREATE TABLE log_activities
(
log_activity_id integer GENERATED ALWAYS AS IDENTITY
CONSTRAINT log_activities_pk
PRIMARY KEY,
activity integer NOT NULL
CONSTRAINT log_activities_activity_fk
REFERENCES activities
ON DELETE RESTRICT,
topics_discussed text NOT NULL,
lecture_description text,
message_url text,
attached_files text,
other_details text,
accepted boolean DEFAULT FALSE NOT NULL,
added_by bigint
CONSTRAINT log_activities_added_by_fk
REFERENCES users
ON DELETE RESTRICT,
added_timestamp timestamp WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
accepted_by bigint
CONSTRAINT log_activities_accepted_by_fk
REFERENCES users
ON DELETE RESTRICT,
accepted_timestamp timestamp WITH TIME ZONE
);
CREATE UNIQUE INDEX log_activities_log_activity_id_uindex
ON log_activities (log_activity_id);
CREATE TABLE log_tests
(
log_test_id integer GENERATED ALWAYS AS IDENTITY
CONSTRAINT log_tests_pk
PRIMARY KEY,
activity integer
CONSTRAINT log_tests_activity_fk
REFERENCES activities
ON DELETE RESTRICT,
test_type text,
num_questions integer,
duration_min integer,
message_url text,
attached_files text,
other_details text,
accepted boolean DEFAULT FALSE NOT NULL,
added_by bigint
CONSTRAINT log_tests_added_by_fk
REFERENCES users
ON DELETE RESTRICT,
added_timestamp timestamp WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
accepted_by bigint
CONSTRAINT log_tests_accepted_by_fk
REFERENCES users
ON DELETE RESTRICT,
accepted_timestamp timestamp WITH TIME ZONE,
exam_timestamp timestamp
);
CREATE UNIQUE INDEX log_tests_log_test_id_uindex
ON log_tests (log_test_id);
CREATE TABLE course_manager
(
course text NOT NULL
CONSTRAINT course_fk
REFERENCES courses
ON DELETE RESTRICT,
manager integer NOT NULL
CONSTRAINT manager_fk
REFERENCES teachers
ON DELETE RESTRICT
);
CREATE UNIQUE INDEX course_manager_uindex
ON course_manager (course, manager);
CREATE TABLE users_groups
(
user_id bigint NOT NULL
CONSTRAINT users_fk
REFERENCES users
ON DELETE RESTRICT,
group_id integer NOT NULL
CONSTRAINT groups_fk
REFERENCES unit_groups
ON DELETE RESTRICT
);
COMMENT ON TABLE users_groups IS 'N groups - N users';
CREATE UNIQUE INDEX user_group_uindex
ON users_groups (user_id, group_id);
CREATE TABLE activities_per_test
(
test_id integer NOT NULL
CONSTRAINT test_fk
REFERENCES log_tests
ON DELETE RESTRICT,
activity_id integer NOT NULL
CONSTRAINT activities_fk
REFERENCES log_activities
ON DELETE RESTRICT
);
CREATE UNIQUE INDEX activities_test_uindex
ON activities_per_test (test_id, activity_id);
CREATE TABLE log_homeworks
(
homework_id integer GENERATED ALWAYS AS IDENTITY
CONSTRAINT log_homeworks_pk
PRIMARY KEY,
hw_short_description text NOT NULL,
hw_full_description text,
hw_turn_in_method text,
hw_due_date timestamp WITH TIME ZONE NOT NULL,
attached_files text,
from_activity integer
CONSTRAINT log_homeworks_from_activity_fk
REFERENCES activities
ON DELETE SET NULL,
added_timestamp timestamp WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
accepted boolean DEFAULT FALSE NOT NULL,
accepted_by bigint
CONSTRAINT log_homeworks_accepted_by_fk
REFERENCES users
ON DELETE SET NULL,
accepted_timestamp timestamp WITH TIME ZONE,
other_details text,
added_by bigint NOT NULL
CONSTRAINT log_homeworks_added_by_fk
REFERENCES users
ON DELETE SET NULL
);
ALTER SEQUENCE log_homeworks_homework_id_seq1 OWNED BY log_homeworks.homework_id;
CREATE UNIQUE INDEX log_homeworks_homework_id_uindex
ON log_homeworks (homework_id);