25
CREATE TABLE subject (
26
subjectid SERIAL PRIMARY KEY NOT NULL,
27
subj_code VARCHAR UNIQUE NOT NULL,
28
subj_name VARCHAR NOT NULL,
29
subj_short_name VARCHAR UNIQUE NOT NULL,
33
CREATE TABLE semester (
34
semesterid SERIAL PRIMARY KEY NOT NULL,
22
CREATE TABLE offering (
23
offeringid SERIAL PRIMARY KEY NOT NULL,
24
subj_name VARCHAR NOT NULL,
25
subj_code VARCHAR NOT NULL,
35
26
year CHAR(4) NOT NULL,
36
27
semester CHAR(1) NOT NULL,
37
state TEXT NOT NULL CHECK (state IN ('disabled', 'past',
38
'current', 'future')) DEFAULT 'current',
39
UNIQUE (year, semester)
42
CREATE TABLE offering (
43
offeringid SERIAL PRIMARY KEY NOT NULL,
44
subject INT4 REFERENCES subject (subjectid) NOT NULL,
45
semesterid INTEGER REFERENCES semester (semesterid) NOT NULL,
46
groups_student_permissions VARCHAR NOT NULL DEFAULT 'none',
47
CHECK (groups_student_permissions in ('none', 'invite', 'create')),
48
UNIQUE (subject, semesterid)
52
CREATE TABLE project_set (
53
projectsetid SERIAL PRIMARY KEY NOT NULL,
54
offeringid INTEGER REFERENCES offering (offeringid) NOT NULL,
55
max_students_per_group INTEGER
58
31
CREATE TABLE project (
59
32
projectid SERIAL PRIMARY KEY NOT NULL,
60
short_name TEXT NOT NULL,
64
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
35
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
68
CREATE OR REPLACE FUNCTION check_project_namespacing_insertupdate()
73
IF TG_OP = ''UPDATE'' THEN
74
IF NEW.projectsetid = OLD.projectsetid AND NEW.short_name = OLD.short_name THEN
78
SELECT offeringid INTO oid FROM project_set WHERE project_set.projectsetid = NEW.projectsetid;
79
PERFORM 1 FROM project, project_set
80
WHERE project_set.offeringid = oid AND
81
project.projectsetid = project_set.projectsetid AND
82
project.short_name = NEW.short_name;
84
RAISE EXCEPTION ''a project named % already exists in offering ID %'', NEW.short_name, oid;
90
CREATE TRIGGER check_project_namespacing
91
BEFORE INSERT OR UPDATE ON project
92
FOR EACH ROW EXECUTE PROCEDURE check_project_namespacing_insertupdate();
94
39
CREATE TABLE project_group (
95
40
groupnm VARCHAR NOT NULL,
96
41
groupid SERIAL PRIMARY KEY NOT NULL,
97
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
42
offeringid INT4 REFERENCES offering (offeringid),
99
44
createdby INT4 REFERENCES login (loginid) NOT NULL,
100
45
epoch TIMESTAMP NOT NULL,
101
UNIQUE (projectsetid, groupnm)
46
UNIQUE (offeringid, groupnm)
104
CREATE OR REPLACE FUNCTION check_group_namespacing_insertupdate()
109
SELECT offeringid INTO oid FROM project_set WHERE project_set.projectsetid = NEW.projectsetid;
110
PERFORM 1 FROM project_group, project_set WHERE project_set.offeringid = oid AND project_group.projectsetid = project_set.projectsetid AND project_group.groupnm = NEW.groupnm;
112
RAISE EXCEPTION ''a project group named % already exists in offering ID %'', NEW.groupnm, oid;
116
' LANGUAGE 'plpgsql';
118
CREATE TRIGGER check_group_namespacing
119
BEFORE INSERT OR UPDATE ON project_group
120
FOR EACH ROW EXECUTE PROCEDURE check_group_namespacing_insertupdate();
122
49
CREATE TABLE group_invitation (
123
50
loginid INT4 REFERENCES login (loginid) NOT NULL,
124
51
groupid INT4 REFERENCES project_group (groupid) NOT NULL,
135
58
CREATE TABLE group_member (
136
59
loginid INT4 REFERENCES login (loginid),
137
60
groupid INT4 REFERENCES project_group (groupid),
61
projectid INT4 REFERENCES project (projectid),
62
UNIQUE (loginid,projectid),
138
63
PRIMARY KEY (loginid,groupid)
141
66
CREATE TABLE enrolment (
142
67
loginid INT4 REFERENCES login (loginid),
143
68
offeringid INT4 REFERENCES offering (offeringid),
144
role TEXT NOT NULL CHECK (role IN ('student', 'tutor',
145
'lecturer')) DEFAULT 'student',
147
70
special_result VARCHAR,
149
72
special_supp_result VARCHAR,
151
active BOOL NOT NULL DEFAULT true,
152
74
PRIMARY KEY (loginid,offeringid)
156
78
assessedid SERIAL PRIMARY KEY NOT NULL,
157
79
loginid INT4 REFERENCES login (loginid),
158
80
groupid INT4 REFERENCES project_group (groupid),
159
projectid INT4 REFERENCES project (projectid) NOT NULL,
160
81
-- exactly one of loginid and groupid must be non-null
161
82
CHECK ((loginid IS NOT NULL AND groupid IS NULL)
162
83
OR (loginid IS NULL AND groupid IS NOT NULL))
165
86
CREATE TABLE project_extension (
166
extensionid SERIAL PRIMARY KEY,
167
87
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
88
projectid INT4 REFERENCES project (projectid) NOT NULL,
168
89
deadline TIMESTAMP NOT NULL,
169
90
approver INT4 REFERENCES login (loginid) NOT NULL,
173
CREATE TABLE project_submission (
174
submissionid SERIAL PRIMARY KEY,
175
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
176
path VARCHAR NOT NULL,
177
revision INT4 NOT NULL,
178
date_submitted TIMESTAMP NOT NULL,
179
submitter INT4 REFERENCES login (loginid) NOT NULL
182
94
CREATE TABLE project_mark (
183
95
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
96
projectid INT4 REFERENCES project (projectid) NOT NULL,
185
98
marker INT4 REFERENCES login (loginid) NOT NULL,
192
CREATE TABLE exercise (
193
identifier TEXT PRIMARY KEY,
202
CREATE TABLE worksheet (
203
worksheetid SERIAL PRIMARY KEY,
204
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
205
identifier TEXT NOT NULL,
208
assessable BOOLEAN NOT NULL,
209
seq_no INT4 NOT NULL,
210
format TEXT NOT NUll,
211
UNIQUE (offeringid, identifier)
214
CREATE TABLE worksheet_exercise (
215
ws_ex_id SERIAL PRIMARY KEY,
216
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
217
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
218
seq_no INT4 NOT NULL,
219
active BOOLEAN NOT NULL DEFAULT true,
220
optional BOOLEAN NOT NULL,
221
UNIQUE (worksheetid, exerciseid)
224
CREATE TABLE exercise_attempt (
105
CREATE TABLE problem (
106
problemid SERIAL PRIMARY KEY NOT NULL,
110
CREATE TABLE problem_tag (
111
problemid INT4 REFERENCES problem (problemid),
112
tag VARCHAR NOT NULL,
114
standard BOOLEAN NOT NULL,
115
added_by INT4 REFERENCES login (loginid) NOT NULL,
116
date TIMESTAMP NOT NULL,
117
PRIMARY KEY (problemid,added_by,tag)
120
CREATE TABLE problem_test_case (
121
problemid INT4 REFERENCES problem (problemid) NOT NULL,
122
testcaseid SERIAL UNIQUE NOT NULL,
125
visibility VARCHAR CHECK (visibility in ('public', 'protected', 'private'))
128
CREATE TABLE problem_test_case_tag (
129
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
130
tag VARCHAR NOT NULL,
132
standard BOOLEAN NOT NULL,
133
added_by INT4 REFERENCES login (loginid) NOT NULL,
134
date TIMESTAMP NOT NULL,
135
PRIMARY KEY (testcaseid,added_by,tag)
138
CREATE TABLE problem_attempt (
139
problemid INT4 REFERENCES problem (problemid) NOT NULL,
225
140
loginid INT4 REFERENCES login (loginid) NOT NULL,
226
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
227
141
date TIMESTAMP NOT NULL,
228
attempt TEXT NOT NULL,
142
attempt VARCHAR NOT NULL,
229
143
complete BOOLEAN NOT NULL,
230
active BOOLEAN NOT NULL DEFAULT true,
231
PRIMARY KEY (loginid, ws_ex_id, date)
144
PRIMARY KEY (problemid,loginid,date)
234
CREATE TABLE exercise_save (
147
CREATE INDEX problem_attempt_index ON problem_attempt (problemid, loginid);
149
CREATE TABLE problem_attempt_breakdown (
150
problemid INT4 REFERENCES problem (problemid) NOT NULL,
151
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
235
152
loginid INT4 REFERENCES login (loginid) NOT NULL,
236
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
237
153
date TIMESTAMP NOT NULL,
239
PRIMARY KEY (loginid, ws_ex_id)
242
CREATE TABLE test_suite (
243
suiteid SERIAL PRIMARY KEY,
244
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
251
CREATE TABLE test_case (
252
testid SERIAL PRIMARY KEY,
253
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
260
CREATE TABLE suite_variable (
261
varid SERIAL PRIMARY KEY,
262
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
265
var_type TEXT NOT NULL,
269
CREATE TABLE test_case_part (
270
partid SERIAL PRIMARY KEY,
271
testid INT4 REFERENCES test_case (testid) NOT NULL,
272
part_type TEXT NOT NULL,
157
CREATE TABLE problem_prerequisite (
158
parent INT4 REFERENCES problem (problemid) NOT NULL,
159
child INT4 REFERENCES problem (problemid) NOT NULL,
160
PRIMARY KEY (parent,child)