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,
33
CREATE TABLE semester (
34
semesterid SERIAL PRIMARY KEY NOT NULL,
22
CREATE TABLE offering (
23
offeringid SERIAL PRIMARY KEY NOT NULL,
24
subj_name VARCHAR NOT NULL,
25
subj_code VARCHAR NOT NULL,
35
26
year CHAR(4) NOT NULL,
36
27
semester CHAR(1) NOT NULL,
37
state TEXT NOT NULL CHECK (state IN ('disabled', 'past',
38
'current', 'future')) DEFAULT 'current',
39
UNIQUE (year, semester)
42
CREATE TABLE offering (
43
offeringid SERIAL PRIMARY KEY NOT NULL,
44
subject INT4 REFERENCES subject (subjectid) NOT NULL,
45
semesterid INTEGER REFERENCES semester (semesterid) NOT NULL,
46
groups_student_permissions VARCHAR NOT NULL DEFAULT 'none',
47
CHECK (groups_student_permissions in ('none', 'invite', 'create')),
48
UNIQUE (subject, semesterid)
52
CREATE TABLE project_set (
53
projectsetid SERIAL PRIMARY KEY NOT NULL,
54
offeringid INTEGER REFERENCES offering (offeringid) NOT NULL,
55
max_students_per_group INTEGER NOT NULL DEFAULT 4
58
31
CREATE TABLE project (
59
32
projectid SERIAL PRIMARY KEY NOT NULL,
62
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
35
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
66
39
CREATE TABLE project_group (
67
40
groupnm VARCHAR NOT NULL,
68
41
groupid SERIAL PRIMARY KEY NOT NULL,
69
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
42
offeringid INT4 REFERENCES offering (offeringid),
71
44
createdby INT4 REFERENCES login (loginid) NOT NULL,
72
45
epoch TIMESTAMP NOT NULL,
73
UNIQUE (projectsetid, groupnm)
46
UNIQUE (offeringid, groupnm)
76
CREATE OR REPLACE FUNCTION check_group_namespacing_insertupdate()
81
SELECT offeringid INTO oid FROM project_set WHERE project_set.projectsetid = NEW.projectsetid;
82
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;
84
RAISE EXCEPTION ''a project group named % already exists in offering ID %'', NEW.groupnm, oid;
90
CREATE TRIGGER check_group_namespacing
91
BEFORE INSERT OR UPDATE ON project_group
92
FOR EACH ROW EXECUTE PROCEDURE check_group_namespacing_insertupdate();
94
49
CREATE TABLE group_invitation (
95
50
loginid INT4 REFERENCES login (loginid) NOT NULL,
96
51
groupid INT4 REFERENCES project_group (groupid) NOT NULL,
107
58
CREATE TABLE group_member (
108
59
loginid INT4 REFERENCES login (loginid),
109
60
groupid INT4 REFERENCES project_group (groupid),
61
projectid INT4 REFERENCES project (projectid),
62
UNIQUE (loginid,projectid),
110
63
PRIMARY KEY (loginid,groupid)
113
66
CREATE TABLE enrolment (
114
67
loginid INT4 REFERENCES login (loginid),
115
68
offeringid INT4 REFERENCES offering (offeringid),
116
role TEXT NOT NULL CHECK (role IN ('student', 'tutor',
117
'lecturer')) DEFAULT 'student',
119
70
special_result VARCHAR,
121
72
special_supp_result VARCHAR,
123
active BOOL NOT NULL DEFAULT true,
124
74
PRIMARY KEY (loginid,offeringid)
160
CREATE TABLE exercise (
161
identifier TEXT PRIMARY KEY,
112
CREATE TABLE problem (
113
problemid SERIAL PRIMARY KEY NOT NULL,
114
identifier VARCHAR UNIQUE NOT NULL,
170
118
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 (
119
worksheetid SERIAL PRIMARY KEY NOT NULL,
120
subject VARCHAR NOT NULL,
121
identifier VARCHAR NOT NULL,
124
UNIQUE (subject, identifier)
127
CREATE TABLE worksheet_problem (
128
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
129
problemid INT4 REFERENCES problem (problemid) NOT NULL,
131
PRIMARY KEY (worksheetid, problemid)
134
CREATE TABLE problem_tag (
135
problemid INT4 REFERENCES problem (problemid),
136
tag VARCHAR NOT NULL,
138
standard BOOLEAN NOT NULL,
139
added_by INT4 REFERENCES login (loginid) NOT NULL,
140
date TIMESTAMP NOT NULL,
141
PRIMARY KEY (problemid,added_by,tag)
144
CREATE TABLE problem_test_case (
145
problemid INT4 REFERENCES problem (problemid) NOT NULL,
146
testcaseid SERIAL UNIQUE NOT NULL,
149
visibility VARCHAR CHECK (visibility in ('public', 'protected', 'private'))
152
CREATE TABLE problem_test_case_tag (
153
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
154
tag VARCHAR NOT NULL,
156
standard BOOLEAN NOT NULL,
157
added_by INT4 REFERENCES login (loginid) NOT NULL,
158
date TIMESTAMP NOT NULL,
159
PRIMARY KEY (testcaseid,added_by,tag)
162
CREATE TABLE problem_attempt (
163
problemid INT4 REFERENCES problem (problemid) NOT NULL,
193
164
loginid INT4 REFERENCES login (loginid) NOT NULL,
194
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
195
165
date TIMESTAMP NOT NULL,
196
attempt TEXT NOT NULL,
166
attempt VARCHAR NOT NULL,
197
167
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,
168
PRIMARY KEY (problemid,loginid,date)
171
CREATE TABLE problem_save (
172
problemid INT4 REFERENCES problem (problemid) NOT NULL,
173
loginid INT4 REFERENCES login (loginid) NOT NULL,
174
date TIMESTAMP NOT NULL,
175
text VARCHAR NOT NULL,
176
PRIMARY KEY (problemid,loginid)
179
CREATE INDEX problem_attempt_index ON problem_attempt (problemid, loginid);
181
CREATE TABLE problem_attempt_breakdown (
182
problemid INT4 REFERENCES problem (problemid) NOT NULL,
183
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
184
loginid INT4 REFERENCES login (loginid) NOT NULL,
185
date TIMESTAMP NOT NULL,
189
CREATE TABLE problem_prerequisite (
190
parent INT4 REFERENCES problem (problemid) NOT NULL,
191
child INT4 REFERENCES problem (problemid) NOT NULL,
192
PRIMARY KEY (parent,child)