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
rolenm VARCHAR NOT NULL CHECK (rolenm in ('anyone', 'student',
13
'lecturer', 'admin')),
14
unixid INT UNIQUE DEFAULT nextval('login_unixid_seq') NOT NULL,
11
15
nick VARCHAR NOT NULL,
12
16
pass_exp TIMESTAMP,
13
17
acct_exp TIMESTAMP,
14
18
last_login TIMESTAMP,
16
21
fullname VARCHAR NOT NULL,
17
studentid VARCHAR -- may be null
22
studentid VARCHAR, -- may be null
29
CREATE TABLE subject (
30
subjectid SERIAL PRIMARY KEY NOT NULL,
31
subj_code VARCHAR UNIQUE NOT NULL,
32
subj_name VARCHAR NOT NULL,
33
subj_short_name VARCHAR UNIQUE NOT NULL,
37
CREATE TABLE semester (
38
semesterid SERIAL PRIMARY KEY NOT NULL,
39
year CHAR(4) NOT NULL,
40
semester CHAR(1) NOT NULL,
42
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();
20
60
CREATE TABLE offering (
21
61
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,
62
subject INT4 REFERENCES subject (subjectid) NOT NULL,
63
semesterid INTEGER REFERENCES semester (semesterid) NOT NULL,
64
groups_student_permissions VARCHAR NOT NULL DEFAULT 'none',
65
CHECK (groups_student_permissions in ('none', 'invite', 'create')),
66
UNIQUE (subject, semesterid)
69
-- Projects and groups
70
-- -------------------
72
CREATE TABLE project_set (
73
projectsetid SERIAL PRIMARY KEY NOT NULL,
74
offeringid INTEGER REFERENCES offering (offeringid) NOT NULL,
75
max_students_per_group INTEGER NOT NULL DEFAULT 4
29
78
CREATE TABLE project (
30
79
projectid SERIAL PRIMARY KEY NOT NULL,
33
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
82
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
37
86
CREATE TABLE project_group (
38
87
groupnm VARCHAR NOT NULL,
39
88
groupid SERIAL PRIMARY KEY NOT NULL,
40
offeringid INT4 REFERENCES offering (offeringid),
89
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
42
91
createdby INT4 REFERENCES login (loginid) NOT NULL,
43
92
epoch TIMESTAMP NOT NULL,
44
UNIQUE (offeringid, groupnm)
93
UNIQUE (projectsetid, groupnm)
96
CREATE OR REPLACE FUNCTION check_group_namespacing_insertupdate()
101
SELECT offeringid INTO oid FROM project_set WHERE project_set.projectsetid = NEW.projectsetid;
102
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;
104
RAISE EXCEPTION ''a project group named % already exists in offering ID %'', NEW.groupnm, oid;
108
' LANGUAGE 'plpgsql';
110
CREATE TRIGGER check_group_namespacing
111
BEFORE INSERT OR UPDATE ON project_group
112
FOR EACH ROW EXECUTE PROCEDURE check_group_namespacing_insertupdate();
47
114
CREATE TABLE group_invitation (
48
115
loginid INT4 REFERENCES login (loginid) NOT NULL,
49
116
groupid INT4 REFERENCES project_group (groupid) NOT NULL,
70
135
special_supp_result VARCHAR,
137
active BOOL NOT NULL DEFAULT true,
72
138
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();
75
158
CREATE TABLE assessed (
76
159
assessedid SERIAL PRIMARY KEY NOT NULL,
77
160
loginid INT4 REFERENCES login (loginid),
78
161
groupid INT4 REFERENCES project_group (groupid),
162
projectid INT4 REFERENCES project (projectid) NOT NULL,
79
163
-- exactly one of loginid and groupid must be non-null
80
164
CHECK ((loginid IS NOT NULL AND groupid IS NULL)
81
165
OR (loginid IS NULL AND groupid IS NOT NULL))
84
168
CREATE TABLE project_extension (
85
169
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
86
projectid INT4 REFERENCES project (projectid) NOT NULL,
87
170
deadline TIMESTAMP NOT NULL,
88
171
approver INT4 REFERENCES login (loginid) NOT NULL,
175
CREATE TABLE project_submission (
176
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
177
path VARCHAR NOT NULL,
178
revision INT4 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
193
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)
194
identifier TEXT PRIMARY KEY,
203
CREATE TABLE worksheet (
204
worksheetid SERIAL PRIMARY KEY,
205
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
206
identifier VARCHAR NOT NULL,
209
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)
136
219
CREATE TABLE problem_attempt (
137
problemid INT4 REFERENCES problem (problemid) NOT NULL,
220
problemid TEXT REFERENCES problem (identifier) NOT NULL,
138
221
loginid INT4 REFERENCES login (loginid) NOT NULL,
222
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
139
223
date TIMESTAMP NOT NULL,
140
224
attempt VARCHAR NOT NULL,
141
225
complete BOOLEAN NOT NULL,
142
PRIMARY KEY (problemid,loginid,date)
226
active BOOLEAN NOT NULL DEFAULT true,
227
PRIMARY KEY (problemid,loginid,worksheetid,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,
230
CREATE TABLE problem_save (
231
problemid TEXT REFERENCES problem (identifier) NOT NULL,
150
232
loginid INT4 REFERENCES login (loginid) NOT NULL,
233
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
151
234
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)
236
PRIMARY KEY (problemid,loginid, worksheetid)
239
CREATE TABLE test_suite (
240
suiteid SERIAL PRIMARY KEY,
241
problemid TEXT REFERENCES problem (identifier) NOT NULL,
248
CREATE TABLE test_case (
249
testid SERIAL PRIMARY KEY,
250
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
257
CREATE TABLE suite_variables (
258
varid SERIAL PRIMARY KEY,
259
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
262
var_type TEXT NOT NULL,
266
CREATE TABLE test_case_parts (
267
partid SERIAL PRIMARY KEY,
268
testid INT4 REFERENCES test_case (testid) NOT NULL,
269
part_type TEXT NOT NULL,