37
36
semesterid SERIAL PRIMARY KEY NOT NULL,
38
37
year CHAR(4) NOT NULL,
39
38
semester CHAR(1) NOT NULL,
39
state TEXT NOT NULL CHECK (state IN ('disabled', 'past',
40
'current', 'future')) DEFAULT 'current',
41
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();
59
44
CREATE TABLE offering (
60
45
offeringid SERIAL PRIMARY KEY NOT NULL,
61
46
subject INT4 REFERENCES subject (subjectid) NOT NULL,
71
56
CREATE TABLE project_set (
72
57
projectsetid SERIAL PRIMARY KEY NOT NULL,
73
58
offeringid INTEGER REFERENCES offering (offeringid) NOT NULL,
74
max_students_per_group INTEGER NOT NULL DEFAULT 4
59
max_students_per_group INTEGER
77
62
CREATE TABLE project (
78
63
projectid SERIAL PRIMARY KEY NOT NULL,
64
short_name TEXT NOT NULL,
81
68
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
69
deadline TIMESTAMP NOT NULL
72
CREATE OR REPLACE FUNCTION check_project_namespacing_insertupdate()
77
IF TG_OP = ''UPDATE'' THEN
78
IF NEW.projectsetid = OLD.projectsetid AND NEW.short_name = OLD.short_name THEN
82
SELECT offeringid INTO oid FROM project_set WHERE project_set.projectsetid = NEW.projectsetid;
83
PERFORM 1 FROM project, project_set
84
WHERE project_set.offeringid = oid AND
85
project.projectsetid = project_set.projectsetid AND
86
project.short_name = NEW.short_name;
88
RAISE EXCEPTION ''a project named % already exists in offering ID %'', NEW.short_name, oid;
94
CREATE TRIGGER check_project_namespacing
95
BEFORE INSERT OR UPDATE ON project
96
FOR EACH ROW EXECUTE PROCEDURE check_project_namespacing_insertupdate();
85
98
CREATE TABLE project_group (
86
99
groupnm VARCHAR NOT NULL,
87
100
groupid SERIAL PRIMARY KEY NOT NULL,
137
152
PRIMARY KEY (loginid,offeringid)
140
CREATE OR REPLACE FUNCTION confirm_active_semester_insertupdate()
145
SELECT semester.active INTO active FROM offering, semester WHERE offeringid=NEW.offeringid AND semester.semesterid = offering.semesterid;
146
IF NOT active AND NEW.active = true THEN
147
RAISE EXCEPTION ''cannot have active enrolment for % in offering %, as the semester is inactive'', NEW.loginid, NEW.offeringid;
151
' LANGUAGE 'plpgsql';
153
CREATE TRIGGER confirm_active_semester
154
BEFORE INSERT OR UPDATE ON enrolment
155
FOR EACH ROW EXECUTE PROCEDURE confirm_active_semester_insertupdate();
157
155
CREATE TABLE assessed (
158
156
assessedid SERIAL PRIMARY KEY NOT NULL,
159
157
loginid INT4 REFERENCES login (loginid),
203
--TODO: Link worksheets to offerings
204
204
CREATE TABLE worksheet (
205
worksheetid SERIAL PRIMARY KEY NOT NULL,
206
subject VARCHAR NOT NULL,
207
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
208
identifier VARCHAR NOT NULL,
211
UNIQUE (subject, identifier)
214
CREATE TABLE worksheet_problem (
215
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
216
problemid TEXT REFERENCES problem (identifier) NOT NULL,
218
PRIMARY KEY (worksheetid, problemid)
221
CREATE TABLE problem_attempt (
222
problemid VARCHAR REFERENCES problem (identifier) NOT NULL,
205
worksheetid SERIAL PRIMARY KEY,
206
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
207
identifier TEXT NOT NULL,
210
assessable BOOLEAN NOT NULL,
211
seq_no INT4 NOT NULL,
212
format TEXT NOT NUll,
213
UNIQUE (offeringid, identifier)
216
CREATE TABLE worksheet_exercise (
217
ws_ex_id SERIAL PRIMARY KEY,
218
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
219
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
220
seq_no INT4 NOT NULL,
221
active BOOLEAN NOT NULL DEFAULT true,
222
optional BOOLEAN NOT NULL,
223
UNIQUE (worksheetid, exerciseid)
226
CREATE TABLE exercise_attempt (
223
227
loginid INT4 REFERENCES login (loginid) NOT NULL,
224
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
228
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
225
229
date TIMESTAMP NOT NULL,
226
attempt VARCHAR NOT NULL,
230
attempt TEXT NOT NULL,
227
231
complete BOOLEAN NOT NULL,
228
232
active BOOLEAN NOT NULL DEFAULT true,
229
PRIMARY KEY (problemid,loginid,date)
233
PRIMARY KEY (loginid, ws_ex_id, date)
232
CREATE TABLE problem_save (
233
problemid INT4 REFERENCES problem (problemid) NOT NULL,
236
CREATE TABLE exercise_save (
234
237
loginid INT4 REFERENCES login (loginid) NOT NULL,
235
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
238
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
236
239
date TIMESTAMP NOT NULL,
237
text VARCHAR NOT NULL,
238
PRIMARY KEY (problemid,loginid)
241
PRIMARY KEY (loginid, ws_ex_id)
241
CREATE INDEX problem_attempt_index ON problem_attempt (problemid, loginid);
243
244
CREATE TABLE test_suite (
244
suiteid SERIAL NOT NULL,
245
problemid TEXT REFERENCES problem (identifier) NOT NULL,
245
suiteid SERIAL PRIMARY KEY,
246
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
246
247
description TEXT,
248
PRIMARY KEY (problemid, suiteid)
251
253
CREATE TABLE test_case (
252
testid SERIAL NOT NULL,
254
testid SERIAL PRIMARY KEY,
255
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
262
CREATE TABLE suite_variable (
263
varid SERIAL PRIMARY KEY,
253
264
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
261
PRIMARY KEY (testid, suiteid)
267
var_type TEXT NOT NULL,
271
CREATE TABLE test_case_part (
272
partid SERIAL PRIMARY KEY,
273
testid INT4 REFERENCES test_case (testid) NOT NULL,
274
part_type TEXT NOT NULL,