38
36
semesterid SERIAL PRIMARY KEY NOT NULL,
39
37
year CHAR(4) NOT NULL,
40
38
semester CHAR(1) NOT NULL,
39
state TEXT NOT NULL CHECK (state IN ('disabled', 'past',
40
'current', 'future')) DEFAULT 'current',
42
41
UNIQUE (year, semester)
45
CREATE OR REPLACE FUNCTION deactivate_semester_enrolments_update()
48
IF OLD.active = true AND NEW.active = false THEN
49
UPDATE enrolment SET active=false WHERE offeringid IN (
50
SELECT offeringid FROM offering WHERE offering.semesterid = NEW.semesterid);
56
CREATE TRIGGER deactivate_semester_enrolments
57
AFTER UPDATE ON semester
58
FOR EACH ROW EXECUTE PROCEDURE deactivate_semester_enrolments_update();
60
44
CREATE TABLE offering (
61
45
offeringid SERIAL PRIMARY KEY NOT NULL,
62
46
subject INT4 REFERENCES subject (subjectid) NOT NULL,
72
56
CREATE TABLE project_set (
73
57
projectsetid SERIAL PRIMARY KEY NOT NULL,
74
58
offeringid INTEGER REFERENCES offering (offeringid) NOT NULL,
75
max_students_per_group INTEGER NOT NULL DEFAULT 4
59
max_students_per_group INTEGER
78
62
CREATE TABLE project (
79
63
projectid SERIAL PRIMARY KEY NOT NULL,
64
short_name TEXT NOT NULL,
82
68
projectsetid INTEGER REFERENCES project_set (projectsetid) 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();
86
98
CREATE TABLE project_group (
87
99
groupnm VARCHAR NOT NULL,
88
100
groupid SERIAL PRIMARY KEY NOT NULL,
138
152
PRIMARY KEY (loginid,offeringid)
141
CREATE OR REPLACE FUNCTION confirm_active_semester_insertupdate()
146
SELECT semester.active INTO active FROM offering, semester WHERE offeringid=NEW.offeringid AND semester.semesterid = offering.semesterid;
147
IF NOT active AND NEW.active = true THEN
148
RAISE EXCEPTION ''cannot have active enrolment for % in offering %, as the semester is inactive'', NEW.loginid, NEW.offeringid;
152
' LANGUAGE 'plpgsql';
154
CREATE TRIGGER confirm_active_semester
155
BEFORE INSERT OR UPDATE ON enrolment
156
FOR EACH ROW EXECUTE PROCEDURE confirm_active_semester_insertupdate();
158
155
CREATE TABLE assessed (
159
156
assessedid SERIAL PRIMARY KEY NOT NULL,
160
157
loginid INT4 REFERENCES login (loginid),
203
204
CREATE TABLE worksheet (
204
205
worksheetid SERIAL PRIMARY KEY,
205
206
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
206
identifier VARCHAR NOT NULL,
207
identifier TEXT NOT NULL,
210
assessable BOOLEAN NOT NULL,
211
seq_no INT4 NOT NULL,
212
format TEXT NOT NUll,
209
213
UNIQUE (offeringid, identifier)
212
CREATE TABLE worksheet_problem (
213
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
214
problemid TEXT REFERENCES problem (identifier) NOT NULL,
216
PRIMARY KEY (worksheetid, problemid)
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)
219
CREATE TABLE problem_attempt (
220
problemid TEXT REFERENCES problem (identifier) NOT NULL,
226
CREATE TABLE exercise_attempt (
221
227
loginid INT4 REFERENCES login (loginid) NOT NULL,
222
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
228
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
223
229
date TIMESTAMP NOT NULL,
224
attempt VARCHAR NOT NULL,
230
attempt TEXT NOT NULL,
225
231
complete BOOLEAN NOT NULL,
226
232
active BOOLEAN NOT NULL DEFAULT true,
227
PRIMARY KEY (problemid,loginid,worksheetid,date)
233
PRIMARY KEY (loginid, ws_ex_id, date)
230
CREATE TABLE problem_save (
231
problemid TEXT REFERENCES problem (identifier) NOT NULL,
236
CREATE TABLE exercise_save (
232
237
loginid INT4 REFERENCES login (loginid) NOT NULL,
233
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
238
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
234
239
date TIMESTAMP NOT NULL,
235
240
text TEXT NOT NULL,
236
PRIMARY KEY (problemid,loginid, worksheetid)
241
PRIMARY KEY (loginid, ws_ex_id)
239
244
CREATE TABLE test_suite (
240
245
suiteid SERIAL PRIMARY KEY,
241
problemid TEXT REFERENCES problem (identifier) NOT NULL,
246
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
242
247
description TEXT,