25
22
CREATE TABLE subject (
26
23
subjectid SERIAL PRIMARY KEY NOT NULL,
27
24
subj_code VARCHAR UNIQUE NOT NULL,
28
25
subj_name VARCHAR NOT NULL,
29
subj_short_name VARCHAR UNIQUE NOT NULL,
26
subj_short_name VARCHAR, -- may be null
33
CREATE TABLE semester (
34
semesterid SERIAL PRIMARY KEY NOT NULL,
35
year CHAR(4) NOT NULL,
36
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
30
CREATE TABLE offering (
43
31
offeringid SERIAL PRIMARY KEY NOT NULL,
44
32
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
33
year CHAR(4) NOT NULL,
34
semester CHAR(1) NOT NULL,
35
UNIQUE (subject, year, semester)
58
38
CREATE TABLE project (
59
39
projectid SERIAL PRIMARY KEY NOT NULL,
62
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
42
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
66
46
CREATE TABLE project_group (
67
47
groupnm VARCHAR NOT NULL,
68
48
groupid SERIAL PRIMARY KEY NOT NULL,
69
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
49
offeringid INT4 REFERENCES offering (offeringid),
71
51
createdby INT4 REFERENCES login (loginid) NOT NULL,
72
52
epoch TIMESTAMP NOT NULL,
73
UNIQUE (projectsetid, groupnm)
53
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
56
CREATE TABLE group_invitation (
95
57
loginid INT4 REFERENCES login (loginid) NOT NULL,
96
58
groupid INT4 REFERENCES project_group (groupid) NOT NULL,
107
65
CREATE TABLE group_member (
108
66
loginid INT4 REFERENCES login (loginid),
109
67
groupid INT4 REFERENCES project_group (groupid),
68
projectid INT4 REFERENCES project (projectid),
69
UNIQUE (loginid,projectid),
110
70
PRIMARY KEY (loginid,groupid)
113
73
CREATE TABLE enrolment (
114
74
loginid INT4 REFERENCES login (loginid),
115
75
offeringid INT4 REFERENCES offering (offeringid),
116
role TEXT NOT NULL CHECK (role IN ('student', 'tutor',
117
'lecturer')) DEFAULT 'student',
119
77
special_result VARCHAR,
121
79
special_supp_result VARCHAR,
123
active BOOL NOT NULL DEFAULT true,
124
81
PRIMARY KEY (loginid,offeringid)
160
CREATE TABLE exercise (
161
identifier TEXT PRIMARY KEY,
119
CREATE TABLE problem (
120
problemid SERIAL PRIMARY KEY NOT NULL,
121
identifier VARCHAR UNIQUE NOT NULL,
170
125
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 (
126
worksheetid SERIAL PRIMARY KEY NOT NULL,
127
subject VARCHAR NOT NULL,
128
identifier VARCHAR NOT NULL,
131
UNIQUE (subject, identifier)
134
CREATE TABLE worksheet_problem (
135
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
136
problemid INT4 REFERENCES problem (problemid) NOT NULL,
138
PRIMARY KEY (worksheetid, problemid)
141
CREATE TABLE problem_tag (
142
problemid INT4 REFERENCES problem (problemid),
143
tag VARCHAR NOT NULL,
145
standard BOOLEAN NOT NULL,
146
added_by INT4 REFERENCES login (loginid) NOT NULL,
147
date TIMESTAMP NOT NULL,
148
PRIMARY KEY (problemid,added_by,tag)
151
CREATE TABLE problem_test_case (
152
problemid INT4 REFERENCES problem (problemid) NOT NULL,
153
testcaseid SERIAL UNIQUE NOT NULL,
156
visibility VARCHAR CHECK (visibility in ('public', 'protected', 'private'))
159
CREATE TABLE problem_test_case_tag (
160
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
161
tag VARCHAR NOT NULL,
163
standard BOOLEAN NOT NULL,
164
added_by INT4 REFERENCES login (loginid) NOT NULL,
165
date TIMESTAMP NOT NULL,
166
PRIMARY KEY (testcaseid,added_by,tag)
169
CREATE TABLE problem_attempt (
170
problemid INT4 REFERENCES problem (problemid) NOT NULL,
193
171
loginid INT4 REFERENCES login (loginid) NOT NULL,
194
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
195
172
date TIMESTAMP NOT NULL,
196
attempt TEXT NOT NULL,
173
attempt VARCHAR NOT NULL,
197
174
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,
175
PRIMARY KEY (problemid,loginid,date)
178
CREATE TABLE problem_save (
179
problemid INT4 REFERENCES problem (problemid) NOT NULL,
180
loginid INT4 REFERENCES login (loginid) NOT NULL,
181
date TIMESTAMP NOT NULL,
182
text VARCHAR NOT NULL,
183
PRIMARY KEY (problemid,loginid)
186
CREATE INDEX problem_attempt_index ON problem_attempt (problemid, loginid);
188
CREATE TABLE problem_attempt_breakdown (
189
problemid INT4 REFERENCES problem (problemid) NOT NULL,
190
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
191
loginid INT4 REFERENCES login (loginid) NOT NULL,
192
date TIMESTAMP NOT NULL,
196
CREATE TABLE problem_prerequisite (
197
parent INT4 REFERENCES problem (problemid) NOT NULL,
198
child INT4 REFERENCES problem (problemid) NOT NULL,
199
PRIMARY KEY (parent,child)