71
56
CREATE TABLE project_set (
72
57
projectsetid SERIAL PRIMARY KEY NOT NULL,
73
58
offeringid INTEGER REFERENCES offering (offeringid) NOT NULL,
74
max_students_per_group INTEGER NOT NULL DEFAULT 4
59
max_students_per_group INTEGER
77
62
CREATE TABLE project (
78
63
projectid SERIAL PRIMARY KEY NOT NULL,
64
short_name TEXT NOT NULL,
81
68
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
69
deadline TIMESTAMP 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();
85
98
CREATE TABLE project_group (
86
99
groupnm VARCHAR NOT NULL,
87
100
groupid SERIAL PRIMARY KEY NOT NULL,
193
CREATE TABLE problem (
194
problemid SERIAL PRIMARY KEY NOT NULL,
195
identifier VARCHAR UNIQUE NOT NULL,
194
CREATE TABLE exercise (
195
identifier TEXT PRIMARY KEY,
199
204
CREATE TABLE worksheet (
200
worksheetid SERIAL PRIMARY KEY NOT NULL,
201
subject VARCHAR NOT NULL,
202
identifier VARCHAR NOT NULL,
205
UNIQUE (subject, identifier)
208
CREATE TABLE worksheet_problem (
209
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
210
problemid INT4 REFERENCES problem (problemid) NOT NULL,
212
PRIMARY KEY (worksheetid, problemid)
215
CREATE TABLE problem_tag (
216
problemid INT4 REFERENCES problem (problemid),
217
tag VARCHAR NOT NULL,
219
standard BOOLEAN NOT NULL,
220
added_by INT4 REFERENCES login (loginid) NOT NULL,
221
date TIMESTAMP NOT NULL,
222
PRIMARY KEY (problemid,added_by,tag)
225
CREATE TABLE problem_test_case (
226
problemid INT4 REFERENCES problem (problemid) NOT NULL,
227
testcaseid SERIAL UNIQUE NOT NULL,
230
visibility VARCHAR CHECK (visibility in ('public', 'protected', 'private'))
233
CREATE TABLE problem_test_case_tag (
234
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
235
tag VARCHAR NOT NULL,
237
standard BOOLEAN NOT NULL,
238
added_by INT4 REFERENCES login (loginid) NOT NULL,
239
date TIMESTAMP NOT NULL,
240
PRIMARY KEY (testcaseid,added_by,tag)
243
CREATE TABLE problem_attempt (
244
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 (
245
227
loginid INT4 REFERENCES login (loginid) NOT NULL,
228
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
246
229
date TIMESTAMP NOT NULL,
247
attempt VARCHAR NOT NULL,
230
attempt TEXT NOT NULL,
248
231
complete BOOLEAN NOT NULL,
249
232
active BOOLEAN NOT NULL DEFAULT true,
250
PRIMARY KEY (problemid,loginid,date)
253
CREATE TABLE problem_save (
254
problemid INT4 REFERENCES problem (problemid) NOT NULL,
255
loginid INT4 REFERENCES login (loginid) NOT NULL,
256
date TIMESTAMP NOT NULL,
257
text VARCHAR NOT NULL,
258
PRIMARY KEY (problemid,loginid)
261
CREATE INDEX problem_attempt_index ON problem_attempt (problemid, loginid);
263
CREATE TABLE problem_attempt_breakdown (
264
problemid INT4 REFERENCES problem (problemid) NOT NULL,
265
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
266
loginid INT4 REFERENCES login (loginid) NOT NULL,
267
date TIMESTAMP NOT NULL,
271
CREATE TABLE problem_prerequisite (
272
parent INT4 REFERENCES problem (problemid) NOT NULL,
273
child INT4 REFERENCES problem (problemid) NOT NULL,
274
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,