4
DROP TABLE group_members;
2
CREATE SEQUENCE login_unixid_seq MINVALUE 1000 MAXVALUE 29999 START WITH 5000;
5
loginid SERIAL PRIMARY KEY NOT NULL,
9
6
login VARCHAR UNIQUE NOT NULL,
10
loginid SERIAL PRIMARY KEY NOT NULL,
8
state VARCHAR NOT NULL CHECK (state in ('no_agreement', 'pending',
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,
15
nick VARCHAR NOT NULL,
21
fullname VARCHAR NOT NULL,
13
22
studentid VARCHAR, -- may be null
17
group VARCHAR NOT 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();
60
CREATE TABLE offering (
61
offeringid SERIAL PRIMARY KEY 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
78
CREATE TABLE project (
79
projectid SERIAL PRIMARY KEY NOT NULL,
82
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
86
CREATE TABLE project_group (
87
groupnm VARCHAR NOT NULL,
18
88
groupid SERIAL PRIMARY KEY NOT NULL,
19
offeringid INT4 REFERENCES offerings (offeringid),
89
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
21
UNIQUE (offeringid, group)
91
createdby INT4 REFERENCES login (loginid) NOT NULL,
92
epoch TIMESTAMP NOT NULL,
93
UNIQUE (projectsetid, groupnm)
24
CREATE TABLE group_invitations (
25
loginid INT4 REFERENCES users (loginid),
26
groupid INT4 REFERENCES groups (groupid),
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();
114
CREATE TABLE group_invitation (
115
loginid INT4 REFERENCES login (loginid) NOT NULL,
116
groupid INT4 REFERENCES project_group (groupid) NOT NULL,
117
inviter INT4 REFERENCES login (loginid) NOT NULL,
118
invited TIMESTAMP NOT NULL,
27
120
UNIQUE (loginid,groupid)
30
CREATE TABLE group_members (
31
loginid INT4 REFERENCES users (loginid),
32
groupid INT4 REFERENCES groups (groupid),
33
projectid INT4 REFERENCES projects (projectid),
34
UNIQUE (loginid,projectid),
123
CREATE TABLE group_member (
124
loginid INT4 REFERENCES login (loginid),
125
groupid INT4 REFERENCES project_group (groupid),
35
126
PRIMARY KEY (loginid,groupid)
38
129
CREATE TABLE enrolment (
39
loginid INT4 REFERENCES users (loginid),
40
offeringid INT4 REFERENCES offerings (offeringid),
130
loginid INT4 REFERENCES login (loginid),
131
offeringid INT4 REFERENCES offering (offeringid),
133
special_result VARCHAR,
135
special_supp_result VARCHAR,
137
active BOOL NOT NULL DEFAULT true,
44
138
PRIMARY KEY (loginid,offeringid)
48
loginid INT4 PRIMARY KEY REFERENCES users (loginid),
52
CREATE TABLE projects (
53
projectid SERIAL PRIMARY KEY NOT NULL,
56
offeringid INT4 REFERENCES offerings (offeringid) NOT NULL,
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
CREATE TABLE assessed (
159
assessedid SERIAL PRIMARY KEY NOT NULL,
160
loginid INT4 REFERENCES login (loginid),
161
groupid INT4 REFERENCES project_group (groupid),
162
projectid INT4 REFERENCES project (projectid) NOT NULL,
163
-- exactly one of loginid and groupid must be non-null
164
CHECK ((loginid IS NOT NULL AND groupid IS NULL)
165
OR (loginid IS NULL AND groupid IS NOT NULL))
60
168
CREATE TABLE project_extension (
62
projectid INT4 REFERENCES projects (projectid) NOT NULL,
169
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
63
170
deadline TIMESTAMP NOT NULL,
64
approver INT4 REFERENCES users (loginid) NOT NULL,
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
68
181
CREATE TABLE project_mark (
70
projectid INT4 REFERENCES projects (projectid) NOT NULL,
182
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
72
marker INT4 REFERENCES users (loginid) NOT NULL,
184
marker INT4 REFERENCES login (loginid) NOT NULL,
77
PRIMARY KEY (loginid/groupid, projectid, componentid)
80
193
CREATE TABLE problem (
81
problemid SERIAL PRIMARY KEY NOT NULL,
85
CREATE TABLE problem_tags (
86
problemid INT4 REFERENCES tutorial_problem (problemid),
88
added_by INT4 REFERENCES users (loginid) NOT NULL,
89
when TIMESTAMP NOT NULL,
90
PRIMARY KEY (problemid,added_by,tag)
93
CREATE TABLE problem_test_case (
94
problemid INT4 REFERENCES problem (problemid) NOT NULL,
95
testcaseid SERIAL UNIQUE NOT NULL,
98
visibility VARCHAR CHECK (visibility in ('public', 'protected', 'private'))
101
CREATE TABLE problem_test_case_tags (
102
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
103
tag VARCHAR NOT NULL,
105
added_by INT4 REFERENCES users (loginid) NOT NULL,
106
when TIMESTAMP NOT NULL,
107
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 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_problem (
216
ws_prob_id SERIAL PRIMARY KEY,
217
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
218
problemid TEXT REFERENCES problem (identifier) NOT NULL,
219
seq_no INT4 NOT NULL,
220
active BOOLEAN NOT NULL DEFAULT true,
221
optional BOOLEAN NOT NULL,
222
UNIQUE (worksheetid, problemid)
110
225
CREATE TABLE problem_attempt (
111
problemid INT4 REFERENCES problem (problemid) NOT NULL,
112
loginid INT4 REFERENCES users (loginid) NOT NULL,
113
when TIMESTAMP NOT NULL,
114
attempt VARCHAR NOT NULL,
226
loginid INT4 REFERENCES login (loginid) NOT NULL,
227
ws_prob_id INT4 REFERENCES worksheet_problem (ws_prob_id) NOT NULL,
228
date TIMESTAMP NOT NULL,
229
attempt TEXT NOT NULL,
115
230
complete BOOLEAN NOT NULL,
116
PRIMARY KEY (problemid,loginid,when)
119
CREATE INDEX indexname ON problem_attempt (problemid, login);
121
CREATE TABLE problem_attempt_breakdown (
122
problemid INT4 REFERENCES problem (problemid) NOT NULL,
123
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
124
loginid INT4 REFERENCES users (loginid) NOT NULL,
125
when TIMESTAMP NOT NULL,
129
CREATE TABLE problem_prerequisites (
130
parent INT4 REFERENCES problem (problemid) NOT NULL,
131
child INT4 REFERENCES problem (problemid) NOT NULL,
132
PRIMARY KEY (parent,child)
231
active BOOLEAN NOT NULL DEFAULT true,
232
PRIMARY KEY (loginid, ws_prob_id, date)
235
CREATE TABLE problem_save (
236
loginid INT4 REFERENCES login (loginid) NOT NULL,
237
ws_prob_id INT4 REFERENCES worksheet_problem (ws_prob_id) NOT NULL,
238
date TIMESTAMP NOT NULL,
240
PRIMARY KEY (loginid, ws_prob_id)
243
CREATE TABLE test_suite (
244
suiteid SERIAL PRIMARY KEY,
245
problemid TEXT REFERENCES problem (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_variables (
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_parts (
271
partid SERIAL PRIMARY KEY,
272
testid INT4 REFERENCES test_case (testid) NOT NULL,
273
part_type TEXT NOT NULL,