2
CREATE SEQUENCE login_unixid_seq MINVALUE 1000 MAXVALUE 29999 START WITH 5000;
5
2
loginid SERIAL PRIMARY KEY NOT NULL,
6
3
login VARCHAR UNIQUE NOT NULL,
8
5
state VARCHAR NOT NULL CHECK (state in ('no_agreement', 'pending',
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,
6
'enabled', 'disabled')),
7
rolenm VARCHAR NOT NULL CHECK (rolenm in ('guest', 'student',
10
unixid INT UNIQUE NOT NULL, -- unix user id
13
11
nick VARCHAR NOT NULL,
14
12
pass_exp TIMESTAMP,
15
13
acct_exp TIMESTAMP,
16
14
last_login TIMESTAMP,
19
16
fullname VARCHAR NOT NULL,
20
studentid VARCHAR, -- may be null
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
32
CREATE TABLE semester (
33
semesterid SERIAL PRIMARY KEY NOT NULL,
17
studentid VARCHAR -- may be null
20
CREATE TABLE offering (
21
offeringid SERIAL PRIMARY KEY NOT NULL,
22
subj_name VARCHAR NOT NULL,
23
subj_code VARCHAR NOT NULL,
34
24
year CHAR(4) NOT NULL,
35
25
semester CHAR(1) NOT NULL,
36
state TEXT NOT NULL CHECK (state IN ('disabled', 'past',
37
'current', 'future')) DEFAULT 'current',
38
UNIQUE (year, semester)
41
CREATE TABLE offering (
42
offeringid SERIAL PRIMARY KEY NOT NULL,
43
subject INT4 REFERENCES subject (subjectid) NOT NULL,
44
semesterid INTEGER REFERENCES semester (semesterid) NOT NULL,
47
groups_student_permissions VARCHAR NOT NULL DEFAULT 'none',
48
CHECK (groups_student_permissions in ('none', 'invite', 'create')),
49
UNIQUE (subject, semesterid)
53
CREATE TABLE project_set (
54
projectsetid SERIAL PRIMARY KEY NOT NULL,
55
offeringid INTEGER REFERENCES offering (offeringid) NOT NULL,
56
max_students_per_group INTEGER
59
29
CREATE TABLE project (
60
30
projectid SERIAL PRIMARY KEY NOT NULL,
61
short_name TEXT NOT NULL,
65
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
66
deadline TIMESTAMP NOT NULL
33
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
69
CREATE OR REPLACE FUNCTION check_project_namespacing_insertupdate()
74
IF TG_OP = ''UPDATE'' THEN
75
IF NEW.projectsetid = OLD.projectsetid AND NEW.short_name = OLD.short_name THEN
79
SELECT offeringid INTO oid FROM project_set WHERE project_set.projectsetid = NEW.projectsetid;
80
PERFORM 1 FROM project, project_set
81
WHERE project_set.offeringid = oid AND
82
project.projectsetid = project_set.projectsetid AND
83
project.short_name = NEW.short_name;
85
RAISE EXCEPTION ''a project named % already exists in offering ID %'', NEW.short_name, oid;
91
CREATE TRIGGER check_project_namespacing
92
BEFORE INSERT OR UPDATE ON project
93
FOR EACH ROW EXECUTE PROCEDURE check_project_namespacing_insertupdate();
95
37
CREATE TABLE project_group (
96
38
groupnm VARCHAR NOT NULL,
97
39
groupid SERIAL PRIMARY KEY NOT NULL,
98
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
40
offeringid INT4 REFERENCES offering (offeringid),
100
42
createdby INT4 REFERENCES login (loginid) NOT NULL,
101
43
epoch TIMESTAMP NOT NULL,
102
UNIQUE (projectsetid, groupnm)
44
UNIQUE (offeringid, groupnm)
105
CREATE OR REPLACE FUNCTION check_group_namespacing_insertupdate()
110
SELECT offeringid INTO oid FROM project_set WHERE project_set.projectsetid = NEW.projectsetid;
111
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;
113
RAISE EXCEPTION ''a project group named % already exists in offering ID %'', NEW.groupnm, oid;
117
' LANGUAGE 'plpgsql';
119
CREATE TRIGGER check_group_namespacing
120
BEFORE INSERT OR UPDATE ON project_group
121
FOR EACH ROW EXECUTE PROCEDURE check_group_namespacing_insertupdate();
123
47
CREATE TABLE group_invitation (
124
48
loginid INT4 REFERENCES login (loginid) NOT NULL,
125
49
groupid INT4 REFERENCES project_group (groupid) NOT NULL,
136
56
CREATE TABLE group_member (
137
57
loginid INT4 REFERENCES login (loginid),
138
58
groupid INT4 REFERENCES project_group (groupid),
59
projectid INT4 REFERENCES project (projectid),
60
UNIQUE (loginid,projectid),
139
61
PRIMARY KEY (loginid,groupid)
142
64
CREATE TABLE enrolment (
143
65
loginid INT4 REFERENCES login (loginid),
144
66
offeringid INT4 REFERENCES offering (offeringid),
145
role TEXT NOT NULL CHECK (role IN ('student', 'tutor',
146
'lecturer')) DEFAULT 'student',
148
68
special_result VARCHAR,
150
70
special_supp_result VARCHAR,
152
active BOOL NOT NULL DEFAULT true,
153
72
PRIMARY KEY (loginid,offeringid)
157
76
assessedid SERIAL PRIMARY KEY NOT NULL,
158
77
loginid INT4 REFERENCES login (loginid),
159
78
groupid INT4 REFERENCES project_group (groupid),
160
projectid INT4 REFERENCES project (projectid) NOT NULL,
161
79
-- exactly one of loginid and groupid must be non-null
162
80
CHECK ((loginid IS NOT NULL AND groupid IS NULL)
163
81
OR (loginid IS NULL AND groupid IS NOT NULL))
166
84
CREATE TABLE project_extension (
167
extensionid SERIAL PRIMARY KEY,
168
85
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
86
projectid INT4 REFERENCES project (projectid) NOT NULL,
169
87
deadline TIMESTAMP NOT NULL,
170
88
approver INT4 REFERENCES login (loginid) NOT NULL,
174
CREATE TABLE project_submission (
175
submissionid SERIAL PRIMARY KEY,
176
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
177
path VARCHAR NOT NULL,
178
revision INT4 NOT NULL,
179
date_submitted TIMESTAMP NOT NULL,
180
submitter INT4 REFERENCES login (loginid) NOT NULL
183
92
CREATE TABLE project_mark (
184
93
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
94
projectid INT4 REFERENCES project (projectid) NOT NULL,
186
96
marker INT4 REFERENCES login (loginid) 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 (
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,
226
138
loginid INT4 REFERENCES login (loginid) NOT NULL,
227
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
228
139
date TIMESTAMP NOT NULL,
229
attempt TEXT NOT NULL,
140
attempt VARCHAR NOT NULL,
230
141
complete BOOLEAN NOT NULL,
231
active BOOLEAN NOT NULL DEFAULT true,
232
PRIMARY KEY (loginid, ws_ex_id, date)
142
PRIMARY KEY (problemid,loginid,date)
235
CREATE TABLE exercise_save (
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,
236
150
loginid INT4 REFERENCES login (loginid) NOT NULL,
237
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
238
151
date TIMESTAMP NOT NULL,
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,
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)