46
28
subjectid SERIAL PRIMARY KEY NOT NULL,
47
29
subj_code VARCHAR UNIQUE NOT NULL,
48
30
subj_name VARCHAR NOT NULL,
49
subj_short_name VARCHAR UNIQUE NOT NULL CHECK (valid_url_name(subj_short_name))
31
subj_short_name VARCHAR UNIQUE NOT NULL,
52
35
CREATE TABLE semester (
53
36
semesterid SERIAL PRIMARY KEY NOT NULL,
54
year CHAR(4) NOT NULL CHECK (valid_url_name(year)),
55
semester CHAR(1) NOT NULL CHECK (valid_url_name(semester)),
56
state TEXT NOT NULL CHECK (state IN ('disabled', 'past',
57
'current', 'future')) DEFAULT 'current',
37
year CHAR(4) NOT NULL,
38
semester CHAR(1) NOT NULL,
58
40
UNIQUE (year, semester)
43
CREATE OR REPLACE FUNCTION deactivate_semester_enrolments_update()
46
IF OLD.active = true AND NEW.active = false THEN
47
UPDATE enrolment SET active=false WHERE offeringid IN (
48
SELECT offeringid FROM offering WHERE offering.semesterid = NEW.semesterid);
54
CREATE TRIGGER deactivate_semester_enrolments
55
AFTER UPDATE ON semester
56
FOR EACH ROW EXECUTE PROCEDURE deactivate_semester_enrolments_update();
61
58
CREATE TABLE offering (
62
59
offeringid SERIAL PRIMARY KEY NOT NULL,
63
60
subject INT4 REFERENCES subject (subjectid) NOT NULL,
64
61
semesterid INTEGER REFERENCES semester (semesterid) NOT NULL,
67
show_worksheet_marks BOOLEAN NOT NULL DEFAULT false,
68
worksheet_cutoff TIMESTAMP,
69
62
groups_student_permissions VARCHAR NOT NULL DEFAULT 'none',
70
63
CHECK (groups_student_permissions in ('none', 'invite', 'create')),
71
64
UNIQUE (subject, semesterid)
77
70
CREATE TABLE project_set (
78
71
projectsetid SERIAL PRIMARY KEY NOT NULL,
79
72
offeringid INTEGER REFERENCES offering (offeringid) NOT NULL,
80
max_students_per_group INTEGER
73
max_students_per_group INTEGER NOT NULL DEFAULT 4
83
76
CREATE TABLE project (
84
77
projectid SERIAL PRIMARY KEY NOT NULL,
85
short_name TEXT NOT NULL CHECK (valid_url_name(short_name)),
89
80
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
90
deadline TIMESTAMP NOT NULL
93
CREATE OR REPLACE FUNCTION check_project_namespacing_insertupdate()
98
IF TG_OP = ''UPDATE'' THEN
99
IF NEW.projectsetid = OLD.projectsetid AND NEW.short_name = OLD.short_name THEN
103
SELECT offeringid INTO oid FROM project_set WHERE project_set.projectsetid = NEW.projectsetid;
104
PERFORM 1 FROM project, project_set
105
WHERE project_set.offeringid = oid AND
106
project.projectsetid = project_set.projectsetid AND
107
project.short_name = NEW.short_name;
109
RAISE EXCEPTION ''a project named % already exists in offering ID %'', NEW.short_name, oid;
113
' LANGUAGE 'plpgsql';
115
CREATE TRIGGER check_project_namespacing
116
BEFORE INSERT OR UPDATE ON project
117
FOR EACH ROW EXECUTE PROCEDURE check_project_namespacing_insertupdate();
119
84
CREATE TABLE project_group (
120
groupnm VARCHAR NOT NULL CHECK (valid_url_name(groupnm)),
85
groupnm VARCHAR NOT NULL,
121
86
groupid SERIAL PRIMARY KEY NOT NULL,
122
87
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
219
CREATE TABLE exercise (
220
identifier TEXT PRIMARY KEY CHECK (valid_url_name(identifier)),
223
description_xhtml_cache TEXT,
192
CREATE TABLE problem (
193
problemid SERIAL PRIMARY KEY NOT NULL,
194
identifier VARCHAR UNIQUE NOT NULL,
230
198
CREATE TABLE worksheet (
231
worksheetid SERIAL PRIMARY KEY,
232
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
233
identifier TEXT NOT NULL CHECK (valid_url_name(identifier)),
236
data_xhtml_cache TEXT,
237
assessable BOOLEAN NOT NULL,
238
published BOOLEAN NOT NULL DEFAULT true,
239
seq_no INT4 NOT NULL,
240
format TEXT NOT NUll,
241
UNIQUE (offeringid, identifier)
244
CREATE TABLE worksheet_exercise (
245
ws_ex_id SERIAL PRIMARY KEY,
246
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
247
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
248
seq_no INT4 NOT NULL,
249
active BOOLEAN NOT NULL DEFAULT true,
250
optional BOOLEAN NOT NULL,
251
UNIQUE (worksheetid, exerciseid)
254
CREATE TABLE exercise_attempt (
199
worksheetid SERIAL PRIMARY KEY NOT NULL,
200
subject VARCHAR NOT NULL,
201
identifier VARCHAR NOT NULL,
204
UNIQUE (subject, identifier)
207
CREATE TABLE worksheet_problem (
208
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
209
problemid INT4 REFERENCES problem (problemid) NOT NULL,
211
PRIMARY KEY (worksheetid, problemid)
214
CREATE TABLE problem_tag (
215
problemid INT4 REFERENCES problem (problemid),
216
tag VARCHAR NOT NULL,
218
standard BOOLEAN NOT NULL,
219
added_by INT4 REFERENCES login (loginid) NOT NULL,
220
date TIMESTAMP NOT NULL,
221
PRIMARY KEY (problemid,added_by,tag)
224
CREATE TABLE problem_test_case (
225
problemid INT4 REFERENCES problem (problemid) NOT NULL,
226
testcaseid SERIAL UNIQUE NOT NULL,
229
visibility VARCHAR CHECK (visibility in ('public', 'protected', 'private'))
232
CREATE TABLE problem_test_case_tag (
233
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
234
tag VARCHAR NOT NULL,
236
standard BOOLEAN NOT NULL,
237
added_by INT4 REFERENCES login (loginid) NOT NULL,
238
date TIMESTAMP NOT NULL,
239
PRIMARY KEY (testcaseid,added_by,tag)
242
CREATE TABLE problem_attempt (
243
problemid INT4 REFERENCES problem (problemid) NOT NULL,
255
244
loginid INT4 REFERENCES login (loginid) NOT NULL,
256
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
257
245
date TIMESTAMP NOT NULL,
258
attempt TEXT NOT NULL,
246
attempt VARCHAR NOT NULL,
259
247
complete BOOLEAN NOT NULL,
260
248
active BOOLEAN NOT NULL DEFAULT true,
261
PRIMARY KEY (loginid, ws_ex_id, date)
264
CREATE TABLE exercise_save (
265
loginid INT4 REFERENCES login (loginid) NOT NULL,
266
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
267
date TIMESTAMP NOT NULL,
269
PRIMARY KEY (loginid, ws_ex_id)
272
CREATE TABLE test_suite (
273
suiteid SERIAL PRIMARY KEY,
274
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
281
CREATE TABLE test_case (
282
testid SERIAL PRIMARY KEY,
283
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
290
CREATE TABLE suite_variable (
291
varid SERIAL PRIMARY KEY,
292
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
295
var_type TEXT NOT NULL,
299
CREATE TABLE test_case_part (
300
partid SERIAL PRIMARY KEY,
301
testid INT4 REFERENCES test_case (testid) NOT NULL,
302
part_type TEXT NOT NULL,
249
PRIMARY KEY (problemid,loginid,date)
252
CREATE TABLE problem_save (
253
problemid INT4 REFERENCES problem (problemid) NOT NULL,
254
loginid INT4 REFERENCES login (loginid) NOT NULL,
255
date TIMESTAMP NOT NULL,
256
text VARCHAR NOT NULL,
257
PRIMARY KEY (problemid,loginid)
260
CREATE INDEX problem_attempt_index ON problem_attempt (problemid, loginid);
262
CREATE TABLE problem_attempt_breakdown (
263
problemid INT4 REFERENCES problem (problemid) NOT NULL,
264
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
265
loginid INT4 REFERENCES login (loginid) NOT NULL,
266
date TIMESTAMP NOT NULL,
270
CREATE TABLE problem_prerequisite (
271
parent INT4 REFERENCES problem (problemid) NOT NULL,
272
child INT4 REFERENCES problem (problemid) NOT NULL,
273
PRIMARY KEY (parent,child)