46
29
subjectid SERIAL PRIMARY KEY NOT NULL,
47
30
subj_code VARCHAR UNIQUE NOT NULL,
48
31
subj_name VARCHAR NOT NULL,
49
subj_short_name VARCHAR UNIQUE NOT NULL CHECK (valid_url_name(subj_short_name))
32
subj_short_name VARCHAR UNIQUE NOT NULL,
52
36
CREATE TABLE semester (
53
37
semesterid SERIAL PRIMARY KEY NOT NULL,
54
year TEXT NOT NULL CHECK (valid_url_name(year)),
55
url_name TEXT NOT NULL CHECK (valid_url_name(url_name)),
57
display_name TEXT NOT NULL,
58
state TEXT NOT NULL CHECK (state IN ('disabled', 'past',
59
'current', 'future')) DEFAULT 'current',
60
UNIQUE (year, url_name),
38
year CHAR(4) NOT NULL,
39
semester CHAR(1) NOT NULL,
41
UNIQUE (year, semester)
44
CREATE OR REPLACE FUNCTION deactivate_semester_enrolments_update()
47
IF OLD.active = true AND NEW.active = false THEN
48
UPDATE enrolment SET active=false WHERE offeringid IN (
49
SELECT offeringid FROM offering WHERE offering.semesterid = NEW.semesterid);
55
CREATE TRIGGER deactivate_semester_enrolments
56
AFTER UPDATE ON semester
57
FOR EACH ROW EXECUTE PROCEDURE deactivate_semester_enrolments_update();
64
59
CREATE TABLE offering (
65
60
offeringid SERIAL PRIMARY KEY NOT NULL,
66
61
subject INT4 REFERENCES subject (subjectid) NOT NULL,
67
62
semesterid INTEGER REFERENCES semester (semesterid) NOT NULL,
70
show_worksheet_marks BOOLEAN NOT NULL DEFAULT false,
71
worksheet_cutoff TIMESTAMP,
72
63
groups_student_permissions VARCHAR NOT NULL DEFAULT 'none',
73
64
CHECK (groups_student_permissions in ('none', 'invite', 'create')),
74
65
UNIQUE (subject, semesterid)
80
71
CREATE TABLE project_set (
81
72
projectsetid SERIAL PRIMARY KEY NOT NULL,
82
73
offeringid INTEGER REFERENCES offering (offeringid) NOT NULL,
83
max_students_per_group INTEGER
74
max_students_per_group INTEGER NOT NULL DEFAULT 4
86
77
CREATE TABLE project (
87
78
projectid SERIAL PRIMARY KEY NOT NULL,
88
short_name TEXT NOT NULL CHECK (valid_url_name(short_name)),
92
81
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
93
deadline TIMESTAMP NOT NULL
96
CREATE OR REPLACE FUNCTION check_project_namespacing_insertupdate()
101
IF TG_OP = ''UPDATE'' THEN
102
IF NEW.projectsetid = OLD.projectsetid AND NEW.short_name = OLD.short_name THEN
106
SELECT offeringid INTO oid FROM project_set WHERE project_set.projectsetid = NEW.projectsetid;
107
PERFORM 1 FROM project, project_set
108
WHERE project_set.offeringid = oid AND
109
project.projectsetid = project_set.projectsetid AND
110
project.short_name = NEW.short_name;
112
RAISE EXCEPTION ''a project named % already exists in offering ID %'', NEW.short_name, oid;
116
' LANGUAGE 'plpgsql';
118
CREATE TRIGGER check_project_namespacing
119
BEFORE INSERT OR UPDATE ON project
120
FOR EACH ROW EXECUTE PROCEDURE check_project_namespacing_insertupdate();
122
85
CREATE TABLE project_group (
123
groupnm VARCHAR NOT NULL CHECK (valid_url_name(groupnm)),
86
groupnm VARCHAR NOT NULL,
124
87
groupid SERIAL PRIMARY KEY NOT NULL,
125
88
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
186
164
OR (loginid IS NULL AND groupid IS NOT NULL))
189
CREATE UNIQUE INDEX assessed_loginid_key ON assessed(loginid, projectid) WHERE loginid IS NOT NULL;
190
CREATE UNIQUE INDEX assessed_groupid_key ON assessed(groupid, projectid) WHERE groupid IS NOT NULL;
192
167
CREATE TABLE project_extension (
193
extensionid SERIAL PRIMARY KEY,
194
168
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
169
deadline TIMESTAMP NOT NULL,
196
170
approver INT4 REFERENCES login (loginid) NOT NULL,
200
174
CREATE TABLE project_submission (
201
submissionid SERIAL PRIMARY KEY,
202
175
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
203
176
path VARCHAR NOT NULL,
204
revision INT4 NOT NULL,
205
date_submitted TIMESTAMP NOT NULL,
206
submitter INT4 REFERENCES login (loginid) NOT NULL
177
revision INT4 NOT NULL
209
180
CREATE TABLE project_mark (
222
CREATE TABLE exercise (
223
identifier TEXT PRIMARY KEY CHECK (valid_url_name(identifier)),
226
description_xhtml_cache TEXT,
193
CREATE TABLE problem (
194
problemid SERIAL PRIMARY KEY NOT NULL,
195
identifier VARCHAR UNIQUE NOT NULL,
233
199
CREATE TABLE worksheet (
234
worksheetid SERIAL PRIMARY KEY,
235
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
236
identifier TEXT NOT NULL CHECK (valid_url_name(identifier)),
239
data_xhtml_cache TEXT,
240
assessable BOOLEAN NOT NULL,
241
published BOOLEAN NOT NULL DEFAULT true,
242
seq_no INT4 NOT NULL,
243
format TEXT NOT NUll,
244
UNIQUE (offeringid, identifier)
247
CREATE TABLE worksheet_exercise (
248
ws_ex_id SERIAL PRIMARY KEY,
249
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
250
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
251
seq_no INT4 NOT NULL,
252
active BOOLEAN NOT NULL DEFAULT true,
253
optional BOOLEAN NOT NULL,
254
UNIQUE (worksheetid, exerciseid)
257
CREATE TABLE exercise_attempt (
200
worksheetid SERIAL PRIMARY KEY NOT NULL,
201
subject VARCHAR NOT NULL,
202
identifier VARCHAR NOT NULL,
205
UNIQUE (subject, identifier)
208
CREATE TABLE worksheet_problem (
209
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
210
problemid INT4 REFERENCES problem (problemid) NOT NULL,
212
PRIMARY KEY (worksheetid, problemid)
215
CREATE TABLE problem_tag (
216
problemid INT4 REFERENCES problem (problemid),
217
tag VARCHAR NOT NULL,
219
standard BOOLEAN NOT NULL,
220
added_by INT4 REFERENCES login (loginid) NOT NULL,
221
date TIMESTAMP NOT NULL,
222
PRIMARY KEY (problemid,added_by,tag)
225
CREATE TABLE problem_test_case (
226
problemid INT4 REFERENCES problem (problemid) NOT NULL,
227
testcaseid SERIAL UNIQUE NOT NULL,
230
visibility VARCHAR CHECK (visibility in ('public', 'protected', 'private'))
233
CREATE TABLE problem_test_case_tag (
234
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
235
tag VARCHAR NOT NULL,
237
standard BOOLEAN NOT NULL,
238
added_by INT4 REFERENCES login (loginid) NOT NULL,
239
date TIMESTAMP NOT NULL,
240
PRIMARY KEY (testcaseid,added_by,tag)
243
CREATE TABLE problem_attempt (
244
problemid INT4 REFERENCES problem (problemid) NOT NULL,
258
245
loginid INT4 REFERENCES login (loginid) NOT NULL,
259
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
260
246
date TIMESTAMP NOT NULL,
261
attempt TEXT NOT NULL,
247
attempt VARCHAR NOT NULL,
262
248
complete BOOLEAN NOT NULL,
263
249
active BOOLEAN NOT NULL DEFAULT true,
264
PRIMARY KEY (loginid, ws_ex_id, date)
267
CREATE TABLE exercise_save (
268
loginid INT4 REFERENCES login (loginid) NOT NULL,
269
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
270
date TIMESTAMP NOT NULL,
272
PRIMARY KEY (loginid, ws_ex_id)
275
CREATE TABLE test_suite (
276
suiteid SERIAL PRIMARY KEY,
277
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
284
CREATE TABLE test_case (
285
testid SERIAL PRIMARY KEY,
286
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
293
CREATE TABLE suite_variable (
294
varid SERIAL PRIMARY KEY,
295
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
298
var_type TEXT NOT NULL,
302
CREATE TABLE test_case_part (
303
partid SERIAL PRIMARY KEY,
304
testid INT4 REFERENCES test_case (testid) NOT NULL,
305
part_type TEXT NOT NULL,
250
PRIMARY KEY (problemid,loginid,date)
253
CREATE TABLE problem_save (
254
problemid INT4 REFERENCES problem (problemid) NOT NULL,
255
loginid INT4 REFERENCES login (loginid) NOT NULL,
256
date TIMESTAMP NOT NULL,
257
text VARCHAR NOT NULL,
258
PRIMARY KEY (problemid,loginid)
261
CREATE INDEX problem_attempt_index ON problem_attempt (problemid, loginid);
263
CREATE TABLE problem_attempt_breakdown (
264
problemid INT4 REFERENCES problem (problemid) NOT NULL,
265
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
266
loginid INT4 REFERENCES login (loginid) NOT NULL,
267
date TIMESTAMP NOT NULL,
271
CREATE TABLE problem_prerequisite (
272
parent INT4 REFERENCES problem (problemid) NOT NULL,
273
child INT4 REFERENCES problem (problemid) NOT NULL,
274
PRIMARY KEY (parent,child)