2
CREATE SEQUENCE login_unixid_seq MINVALUE 1000 MAXVALUE 29999 START WITH 5000;
2
5
loginid SERIAL PRIMARY KEY NOT NULL,
3
6
login VARCHAR UNIQUE NOT NULL,
5
8
state VARCHAR NOT NULL CHECK (state in ('no_agreement', 'pending',
6
'enabled', 'disabled')),
7
rolenm VARCHAR NOT NULL CHECK (rolenm in ('guest', 'student',
10
unixid INT UNIQUE NOT NULL, -- unix user id
9
'enabled', 'disabled'))
10
DEFAULT 'no_agreement',
11
admin BOOLEAN NOT NULL DEFAULT false,
12
unixid INT UNIQUE DEFAULT nextval('login_unixid_seq') NOT NULL,
11
13
nick VARCHAR NOT NULL,
12
14
pass_exp TIMESTAMP,
13
15
acct_exp TIMESTAMP,
14
16
last_login TIMESTAMP,
16
19
fullname VARCHAR NOT NULL,
17
studentid VARCHAR -- may be null
20
studentid VARCHAR, -- may be null
27
CREATE TABLE subject (
28
subjectid SERIAL PRIMARY KEY NOT NULL,
29
subj_code VARCHAR UNIQUE NOT NULL,
30
subj_name VARCHAR NOT NULL,
31
subj_short_name VARCHAR UNIQUE NOT NULL,
35
CREATE TABLE semester (
36
semesterid SERIAL PRIMARY KEY NOT NULL,
37
year CHAR(4) NOT NULL,
38
semester CHAR(1) NOT NULL,
39
state TEXT NOT NULL CHECK (state IN ('disabled', 'past',
40
'current', 'future')) DEFAULT 'current',
41
UNIQUE (year, semester)
20
44
CREATE TABLE offering (
21
45
offeringid SERIAL PRIMARY KEY NOT NULL,
22
subj_name VARCHAR NOT NULL,
23
subj_code VARCHAR NOT NULL,
24
year CHAR(4) NOT NULL,
25
semester CHAR(1) NOT NULL,
46
subject INT4 REFERENCES subject (subjectid) NOT NULL,
47
semesterid INTEGER REFERENCES semester (semesterid) NOT NULL,
48
groups_student_permissions VARCHAR NOT NULL DEFAULT 'none',
49
CHECK (groups_student_permissions in ('none', 'invite', 'create')),
50
UNIQUE (subject, semesterid)
53
-- Projects and groups
54
-- -------------------
56
CREATE TABLE project_set (
57
projectsetid SERIAL PRIMARY KEY NOT NULL,
58
offeringid INTEGER REFERENCES offering (offeringid) NOT NULL,
59
max_students_per_group INTEGER NOT NULL DEFAULT 4
29
62
CREATE TABLE project (
30
63
projectid SERIAL PRIMARY KEY NOT NULL,
33
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
64
short_name TEXT NOT NULL,
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();
37
98
CREATE TABLE project_group (
38
99
groupnm VARCHAR NOT NULL,
39
100
groupid SERIAL PRIMARY KEY NOT NULL,
40
offeringid INT4 REFERENCES offering (offeringid),
101
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
42
103
createdby INT4 REFERENCES login (loginid) NOT NULL,
43
104
epoch TIMESTAMP NOT NULL,
44
UNIQUE (offeringid, groupnm)
105
UNIQUE (projectsetid, groupnm)
108
CREATE OR REPLACE FUNCTION check_group_namespacing_insertupdate()
113
SELECT offeringid INTO oid FROM project_set WHERE project_set.projectsetid = NEW.projectsetid;
114
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;
116
RAISE EXCEPTION ''a project group named % already exists in offering ID %'', NEW.groupnm, oid;
120
' LANGUAGE 'plpgsql';
122
CREATE TRIGGER check_group_namespacing
123
BEFORE INSERT OR UPDATE ON project_group
124
FOR EACH ROW EXECUTE PROCEDURE check_group_namespacing_insertupdate();
47
126
CREATE TABLE group_invitation (
48
127
loginid INT4 REFERENCES login (loginid) NOT NULL,
49
128
groupid INT4 REFERENCES project_group (groupid) NOT NULL,
56
135
CREATE TABLE group_member (
57
136
loginid INT4 REFERENCES login (loginid),
58
137
groupid INT4 REFERENCES project_group (groupid),
59
projectid INT4 REFERENCES project (projectid),
60
UNIQUE (loginid,projectid),
61
138
PRIMARY KEY (loginid,groupid)
64
141
CREATE TABLE enrolment (
65
142
loginid INT4 REFERENCES login (loginid),
66
143
offeringid INT4 REFERENCES offering (offeringid),
144
role TEXT NOT NULL CHECK (role IN ('student', 'tutor',
145
'lecturer')) DEFAULT 'student',
68
147
special_result VARCHAR,
70
149
special_supp_result VARCHAR,
151
active BOOL NOT NULL DEFAULT true,
72
152
PRIMARY KEY (loginid,offeringid)
76
156
assessedid SERIAL PRIMARY KEY NOT NULL,
77
157
loginid INT4 REFERENCES login (loginid),
78
158
groupid INT4 REFERENCES project_group (groupid),
159
projectid INT4 REFERENCES project (projectid) NOT NULL,
79
160
-- exactly one of loginid and groupid must be non-null
80
161
CHECK ((loginid IS NOT NULL AND groupid IS NULL)
81
162
OR (loginid IS NULL AND groupid IS NOT NULL))
84
165
CREATE TABLE project_extension (
166
extensionid SERIAL PRIMARY KEY,
85
167
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
86
projectid INT4 REFERENCES project (projectid) NOT NULL,
87
168
deadline TIMESTAMP NOT NULL,
88
169
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
92
181
CREATE TABLE project_mark (
93
182
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
94
projectid INT4 REFERENCES project (projectid) NOT NULL,
96
184
marker INT4 REFERENCES login (loginid) NOT NULL,
103
CREATE TABLE problem (
104
problemid SERIAL PRIMARY KEY NOT NULL,
108
CREATE TABLE problem_tag (
109
problemid INT4 REFERENCES problem (problemid),
110
tag VARCHAR NOT NULL,
112
standard BOOLEAN NOT NULL,
113
added_by INT4 REFERENCES login (loginid) NOT NULL,
114
date TIMESTAMP NOT NULL,
115
PRIMARY KEY (problemid,added_by,tag)
118
CREATE TABLE problem_test_case (
119
problemid INT4 REFERENCES problem (problemid) NOT NULL,
120
testcaseid SERIAL UNIQUE NOT NULL,
123
visibility VARCHAR CHECK (visibility in ('public', 'protected', 'private'))
126
CREATE TABLE problem_test_case_tag (
127
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
128
tag VARCHAR NOT NULL,
130
standard BOOLEAN NOT NULL,
131
added_by INT4 REFERENCES login (loginid) NOT NULL,
132
date TIMESTAMP NOT NULL,
133
PRIMARY KEY (testcaseid,added_by,tag)
136
CREATE TABLE problem_attempt (
137
problemid INT4 REFERENCES problem (problemid) NOT NULL,
193
CREATE TABLE exercise (
194
identifier TEXT PRIMARY KEY,
203
CREATE TABLE worksheet (
204
worksheetid SERIAL PRIMARY KEY,
205
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
206
identifier TEXT NOT NULL,
209
assessable BOOLEAN NOT NULL,
210
seq_no INT4 NOT NULL,
211
format TEXT NOT NUll,
212
UNIQUE (offeringid, identifier)
215
CREATE TABLE worksheet_exercise (
216
ws_ex_id SERIAL PRIMARY KEY,
217
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
218
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
219
seq_no INT4 NOT NULL,
220
active BOOLEAN NOT NULL DEFAULT true,
221
optional BOOLEAN NOT NULL,
222
UNIQUE (worksheetid, exerciseid)
225
CREATE TABLE exercise_attempt (
138
226
loginid INT4 REFERENCES login (loginid) NOT NULL,
227
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
139
228
date TIMESTAMP NOT NULL,
140
attempt VARCHAR NOT NULL,
229
attempt TEXT NOT NULL,
141
230
complete BOOLEAN NOT NULL,
142
PRIMARY KEY (problemid,loginid,date)
231
active BOOLEAN NOT NULL DEFAULT true,
232
PRIMARY KEY (loginid, ws_ex_id, date)
145
CREATE INDEX problem_attempt_index ON problem_attempt (problemid, loginid);
147
CREATE TABLE problem_attempt_breakdown (
148
problemid INT4 REFERENCES problem (problemid) NOT NULL,
149
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
235
CREATE TABLE exercise_save (
150
236
loginid INT4 REFERENCES login (loginid) NOT NULL,
237
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
151
238
date TIMESTAMP NOT NULL,
155
CREATE TABLE problem_prerequisite (
156
parent INT4 REFERENCES problem (problemid) NOT NULL,
157
child INT4 REFERENCES problem (problemid) NOT NULL,
158
PRIMARY KEY (parent,child)
240
PRIMARY KEY (loginid, ws_ex_id)
243
CREATE TABLE test_suite (
244
suiteid SERIAL PRIMARY KEY,
245
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
252
CREATE TABLE test_case (
253
testid SERIAL PRIMARY KEY,
254
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
261
CREATE TABLE suite_variable (
262
varid SERIAL PRIMARY KEY,
263
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
266
var_type TEXT NOT NULL,
270
CREATE TABLE test_case_part (
271
partid SERIAL PRIMARY KEY,
272
testid INT4 REFERENCES test_case (testid) NOT NULL,
273
part_type TEXT NOT NULL,