8
8
state VARCHAR NOT NULL CHECK (state in ('no_agreement', 'pending',
9
9
'enabled', 'disabled'))
10
10
DEFAULT 'no_agreement',
11
rolenm VARCHAR NOT NULL CHECK (rolenm in ('anyone', 'student',
13
'lecturer', 'admin')),
11
admin BOOLEAN NOT NULL DEFAULT false,
14
12
unixid INT UNIQUE DEFAULT nextval('login_unixid_seq') NOT NULL,
15
13
nick VARCHAR NOT NULL,
16
14
pass_exp TIMESTAMP,
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,
129
141
CREATE TABLE enrolment (
130
142
loginid INT4 REFERENCES login (loginid),
131
143
offeringid INT4 REFERENCES offering (offeringid),
144
role TEXT NOT NULL CHECK (role IN ('student', 'tutor',
145
'lecturer')) DEFAULT 'student',
133
147
special_result VARCHAR,
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),
168
165
CREATE TABLE project_extension (
166
extensionid SERIAL PRIMARY KEY,
169
167
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
170
168
deadline TIMESTAMP NOT NULL,
171
169
approver INT4 REFERENCES login (loginid) NOT NULL,
175
173
CREATE TABLE project_submission (
174
submissionid SERIAL PRIMARY KEY,
176
175
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
177
176
path VARCHAR NOT NULL,
178
revision INT4 NOT NULL
177
revision INT4 NOT NULL,
178
date_submitted TIMESTAMP NOT NULL,
179
submitter INT4 REFERENCES login (loginid) NOT NULL
181
182
CREATE TABLE project_mark (
212
213
UNIQUE (offeringid, identifier)
215
CREATE TABLE worksheet_problem (
216
ws_prob_id SERIAL PRIMARY KEY,
216
CREATE TABLE worksheet_exercise (
217
ws_ex_id SERIAL PRIMARY KEY,
217
218
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
218
problemid TEXT REFERENCES problem (identifier) NOT NULL,
219
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
219
220
seq_no INT4 NOT NULL,
220
221
active BOOLEAN NOT NULL DEFAULT true,
221
222
optional BOOLEAN NOT NULL,
222
UNIQUE (worksheetid, problemid)
223
UNIQUE (worksheetid, exerciseid)
225
CREATE TABLE problem_attempt (
226
CREATE TABLE exercise_attempt (
226
227
loginid INT4 REFERENCES login (loginid) NOT NULL,
227
ws_prob_id INT4 REFERENCES worksheet_problem (ws_prob_id) NOT NULL,
228
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
228
229
date TIMESTAMP NOT NULL,
229
230
attempt TEXT NOT NULL,
230
231
complete BOOLEAN NOT NULL,
231
232
active BOOLEAN NOT NULL DEFAULT true,
232
PRIMARY KEY (loginid, ws_prob_id, date)
233
PRIMARY KEY (loginid, ws_ex_id, date)
235
CREATE TABLE problem_save (
236
CREATE TABLE exercise_save (
236
237
loginid INT4 REFERENCES login (loginid) NOT NULL,
237
ws_prob_id INT4 REFERENCES worksheet_problem (ws_prob_id) NOT NULL,
238
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
238
239
date TIMESTAMP NOT NULL,
239
240
text TEXT NOT NULL,
240
PRIMARY KEY (loginid, ws_prob_id)
241
PRIMARY KEY (loginid, ws_ex_id)
243
244
CREATE TABLE test_suite (
244
245
suiteid SERIAL PRIMARY KEY,
245
problemid TEXT REFERENCES problem (identifier) NOT NULL,
246
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
246
247
description TEXT,