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)
44
30
CREATE TABLE offering (
45
31
offeringid SERIAL PRIMARY KEY NOT NULL,
46
32
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)
54
CREATE TABLE project_set (
55
projectsetid SERIAL PRIMARY KEY NOT NULL,
56
offeringid INTEGER REFERENCES offering (offeringid) NOT NULL,
57
max_students_per_group INTEGER NOT NULL DEFAULT 4
33
year CHAR(4) NOT NULL,
34
semester CHAR(1) NOT NULL,
35
max_groups_per_student INT4 DEFAULT 1,
36
max_students_per_group INT4 DEFAULT 4,
37
groups_student_permissions VARCHAR NOT NULL
38
CHECK (groups_student_permissions in ('none', 'invite',
41
UNIQUE (subject, year, semester)
60
44
CREATE TABLE project (
61
45
projectid SERIAL PRIMARY KEY NOT NULL,
64
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
48
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
68
52
CREATE TABLE project_group (
69
53
groupnm VARCHAR NOT NULL,
70
54
groupid SERIAL PRIMARY KEY NOT NULL,
71
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
55
offeringid INT4 REFERENCES offering (offeringid),
73
57
createdby INT4 REFERENCES login (loginid) NOT NULL,
74
58
epoch TIMESTAMP NOT NULL,
75
UNIQUE (projectsetid, groupnm)
59
UNIQUE (offeringid, groupnm)
78
CREATE OR REPLACE FUNCTION check_group_namespacing_insertupdate()
83
SELECT offeringid INTO oid FROM project_set WHERE project_set.projectsetid = NEW.projectsetid;
84
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;
86
RAISE EXCEPTION ''a project group named % already exists in offering ID %'', NEW.groupnm, oid;
92
CREATE TRIGGER check_group_namespacing
93
BEFORE INSERT OR UPDATE ON project_group
94
FOR EACH ROW EXECUTE PROCEDURE check_group_namespacing_insertupdate();
96
62
CREATE TABLE group_invitation (
97
63
loginid INT4 REFERENCES login (loginid) NOT NULL,
98
64
groupid INT4 REFERENCES project_group (groupid) NOT NULL,
107
71
CREATE TABLE group_member (
108
72
loginid INT4 REFERENCES login (loginid),
109
73
groupid INT4 REFERENCES project_group (groupid),
74
projectid INT4 REFERENCES project (projectid),
75
UNIQUE (loginid,projectid),
110
76
PRIMARY KEY (loginid,groupid)
113
79
CREATE TABLE enrolment (
114
80
loginid INT4 REFERENCES login (loginid),
115
81
offeringid INT4 REFERENCES offering (offeringid),
116
role TEXT NOT NULL CHECK (role IN ('student', 'tutor',
117
'lecturer')) DEFAULT 'student',
119
83
special_result VARCHAR,
121
85
special_supp_result VARCHAR,
123
active BOOL NOT NULL DEFAULT true,
124
87
PRIMARY KEY (loginid,offeringid)
160
CREATE TABLE exercise (
161
identifier TEXT PRIMARY KEY,
123
CREATE TABLE problem (
124
problemid SERIAL PRIMARY KEY NOT NULL,
125
identifier VARCHAR UNIQUE NOT NULL,
170
129
CREATE TABLE worksheet (
171
worksheetid SERIAL PRIMARY KEY,
172
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
173
identifier TEXT NOT NULL,
176
assessable BOOLEAN NOT NULL,
177
seq_no INT4 NOT NULL,
178
format TEXT NOT NUll,
179
UNIQUE (offeringid, identifier)
182
CREATE TABLE worksheet_exercise (
183
ws_ex_id SERIAL PRIMARY KEY,
184
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
185
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
186
seq_no INT4 NOT NULL,
187
active BOOLEAN NOT NULL DEFAULT true,
188
optional BOOLEAN NOT NULL,
189
UNIQUE (worksheetid, exerciseid)
192
CREATE TABLE exercise_attempt (
130
worksheetid SERIAL PRIMARY KEY NOT NULL,
131
subject VARCHAR NOT NULL,
132
identifier VARCHAR NOT NULL,
135
UNIQUE (subject, identifier)
138
CREATE TABLE worksheet_problem (
139
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
140
problemid INT4 REFERENCES problem (problemid) NOT NULL,
142
PRIMARY KEY (worksheetid, problemid)
145
CREATE TABLE problem_tag (
146
problemid INT4 REFERENCES problem (problemid),
147
tag VARCHAR NOT NULL,
149
standard BOOLEAN NOT NULL,
150
added_by INT4 REFERENCES login (loginid) NOT NULL,
151
date TIMESTAMP NOT NULL,
152
PRIMARY KEY (problemid,added_by,tag)
155
CREATE TABLE problem_test_case (
156
problemid INT4 REFERENCES problem (problemid) NOT NULL,
157
testcaseid SERIAL UNIQUE NOT NULL,
160
visibility VARCHAR CHECK (visibility in ('public', 'protected', 'private'))
163
CREATE TABLE problem_test_case_tag (
164
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
165
tag VARCHAR NOT NULL,
167
standard BOOLEAN NOT NULL,
168
added_by INT4 REFERENCES login (loginid) NOT NULL,
169
date TIMESTAMP NOT NULL,
170
PRIMARY KEY (testcaseid,added_by,tag)
173
CREATE TABLE problem_attempt (
174
problemid INT4 REFERENCES problem (problemid) NOT NULL,
193
175
loginid INT4 REFERENCES login (loginid) NOT NULL,
194
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
195
176
date TIMESTAMP NOT NULL,
196
attempt TEXT NOT NULL,
177
attempt VARCHAR NOT NULL,
197
178
complete BOOLEAN NOT NULL,
198
active BOOLEAN NOT NULL DEFAULT true,
199
PRIMARY KEY (loginid, ws_ex_id, date)
202
CREATE TABLE exercise_save (
203
loginid INT4 REFERENCES login (loginid) NOT NULL,
204
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
205
date TIMESTAMP NOT NULL,
207
PRIMARY KEY (loginid, ws_ex_id)
210
CREATE TABLE test_suite (
211
suiteid SERIAL PRIMARY KEY,
212
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
219
CREATE TABLE test_case (
220
testid SERIAL PRIMARY KEY,
221
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
228
CREATE TABLE suite_variable (
229
varid SERIAL PRIMARY KEY,
230
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
233
var_type TEXT NOT NULL,
237
CREATE TABLE test_case_part (
238
partid SERIAL PRIMARY KEY,
239
testid INT4 REFERENCES test_case (testid) NOT NULL,
240
part_type TEXT NOT NULL,
179
PRIMARY KEY (problemid,loginid,date)
182
CREATE TABLE problem_save (
183
problemid INT4 REFERENCES problem (problemid) NOT NULL,
184
loginid INT4 REFERENCES login (loginid) NOT NULL,
185
date TIMESTAMP NOT NULL,
186
text VARCHAR NOT NULL,
187
PRIMARY KEY (problemid,loginid)
190
CREATE INDEX problem_attempt_index ON problem_attempt (problemid, loginid);
192
CREATE TABLE problem_attempt_breakdown (
193
problemid INT4 REFERENCES problem (problemid) NOT NULL,
194
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
195
loginid INT4 REFERENCES login (loginid) NOT NULL,
196
date TIMESTAMP NOT NULL,
200
CREATE TABLE problem_prerequisite (
201
parent INT4 REFERENCES problem (problemid) NOT NULL,
202
child INT4 REFERENCES problem (problemid) NOT NULL,
203
PRIMARY KEY (parent,child)