70
56
CREATE TABLE project_set (
71
57
projectsetid SERIAL PRIMARY KEY NOT NULL,
72
58
offeringid INTEGER REFERENCES offering (offeringid) NOT NULL,
73
max_students_per_group INTEGER NOT NULL DEFAULT 4
59
max_students_per_group INTEGER
76
62
CREATE TABLE project (
77
63
projectid SERIAL PRIMARY KEY NOT NULL,
64
short_name TEXT NOT NULL,
80
68
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
72
CREATE OR REPLACE FUNCTION check_project_namespacing_insertupdate()
77
IF TG_OP = ''UPDATE'' THEN
78
IF NEW.projectsetid = OLD.projectsetid AND NEW.short_name = OLD.short_name THEN
82
SELECT offeringid INTO oid FROM project_set WHERE project_set.projectsetid = NEW.projectsetid;
83
PERFORM 1 FROM project, project_set
84
WHERE project_set.offeringid = oid AND
85
project.projectsetid = project_set.projectsetid AND
86
project.short_name = NEW.short_name;
88
RAISE EXCEPTION ''a project named % already exists in offering ID %'', NEW.short_name, oid;
94
CREATE TRIGGER check_project_namespacing
95
BEFORE INSERT OR UPDATE ON project
96
FOR EACH ROW EXECUTE PROCEDURE check_project_namespacing_insertupdate();
84
98
CREATE TABLE project_group (
85
99
groupnm VARCHAR NOT NULL,
86
100
groupid SERIAL PRIMARY KEY NOT NULL,
192
CREATE TABLE problem (
193
problemid SERIAL PRIMARY KEY NOT NULL,
194
identifier VARCHAR UNIQUE NOT NULL,
194
CREATE TABLE exercise (
195
identifier TEXT PRIMARY KEY,
198
204
CREATE TABLE worksheet (
199
worksheetid SERIAL PRIMARY KEY NOT NULL,
200
subject VARCHAR NOT NULL,
201
identifier VARCHAR NOT NULL,
204
UNIQUE (subject, identifier)
207
CREATE TABLE worksheet_problem (
208
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
209
problemid INT4 REFERENCES problem (problemid) NOT NULL,
211
PRIMARY KEY (worksheetid, problemid)
214
CREATE TABLE problem_tag (
215
problemid INT4 REFERENCES problem (problemid),
216
tag VARCHAR NOT NULL,
218
standard BOOLEAN NOT NULL,
219
added_by INT4 REFERENCES login (loginid) NOT NULL,
220
date TIMESTAMP NOT NULL,
221
PRIMARY KEY (problemid,added_by,tag)
224
CREATE TABLE problem_test_case (
225
problemid INT4 REFERENCES problem (problemid) NOT NULL,
226
testcaseid SERIAL UNIQUE NOT NULL,
229
visibility VARCHAR CHECK (visibility in ('public', 'protected', 'private'))
232
CREATE TABLE problem_test_case_tag (
233
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
234
tag VARCHAR NOT NULL,
236
standard BOOLEAN NOT NULL,
237
added_by INT4 REFERENCES login (loginid) NOT NULL,
238
date TIMESTAMP NOT NULL,
239
PRIMARY KEY (testcaseid,added_by,tag)
242
CREATE TABLE problem_attempt (
243
problemid INT4 REFERENCES problem (problemid) NOT NULL,
205
worksheetid SERIAL PRIMARY KEY,
206
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
207
identifier TEXT NOT NULL,
210
assessable BOOLEAN NOT NULL,
211
seq_no INT4 NOT NULL,
212
format TEXT NOT NUll,
213
UNIQUE (offeringid, identifier)
216
CREATE TABLE worksheet_exercise (
217
ws_ex_id SERIAL PRIMARY KEY,
218
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
219
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
220
seq_no INT4 NOT NULL,
221
active BOOLEAN NOT NULL DEFAULT true,
222
optional BOOLEAN NOT NULL,
223
UNIQUE (worksheetid, exerciseid)
226
CREATE TABLE exercise_attempt (
244
227
loginid INT4 REFERENCES login (loginid) NOT NULL,
228
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
245
229
date TIMESTAMP NOT NULL,
246
attempt VARCHAR NOT NULL,
230
attempt TEXT NOT NULL,
247
231
complete BOOLEAN NOT NULL,
248
232
active BOOLEAN NOT NULL DEFAULT true,
249
PRIMARY KEY (problemid,loginid,date)
252
CREATE TABLE problem_save (
253
problemid INT4 REFERENCES problem (problemid) NOT NULL,
254
loginid INT4 REFERENCES login (loginid) NOT NULL,
255
date TIMESTAMP NOT NULL,
256
text VARCHAR NOT NULL,
257
PRIMARY KEY (problemid,loginid)
260
CREATE INDEX problem_attempt_index ON problem_attempt (problemid, loginid);
262
CREATE TABLE problem_attempt_breakdown (
263
problemid INT4 REFERENCES problem (problemid) NOT NULL,
264
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
265
loginid INT4 REFERENCES login (loginid) NOT NULL,
266
date TIMESTAMP NOT NULL,
270
CREATE TABLE problem_prerequisite (
271
parent INT4 REFERENCES problem (problemid) NOT NULL,
272
child INT4 REFERENCES problem (problemid) NOT NULL,
273
PRIMARY KEY (parent,child)
233
PRIMARY KEY (loginid, ws_ex_id, date)
236
CREATE TABLE exercise_save (
237
loginid INT4 REFERENCES login (loginid) NOT NULL,
238
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
239
date TIMESTAMP NOT NULL,
241
PRIMARY KEY (loginid, ws_ex_id)
244
CREATE TABLE test_suite (
245
suiteid SERIAL PRIMARY KEY,
246
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
253
CREATE TABLE test_case (
254
testid SERIAL PRIMARY KEY,
255
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
262
CREATE TABLE suite_variable (
263
varid SERIAL PRIMARY KEY,
264
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
267
var_type TEXT NOT NULL,
271
CREATE TABLE test_case_part (
272
partid SERIAL PRIMARY KEY,
273
testid INT4 REFERENCES test_case (testid) NOT NULL,
274
part_type TEXT NOT NULL,