1
DROP TABLE users CASCADE;
2
CREATE SEQUENCE login_unixid_seq MINVALUE 1000 MAXVALUE 29999 START WITH 5000;
5
loginid SERIAL PRIMARY KEY NOT NULL,
3
6
login VARCHAR UNIQUE NOT NULL,
4
loginid SERIAL PRIMARY KEY NOT NULL,
7
studentid VARCHAR -- may be null
10
DROP TABLE offerings CASCADE;
11
CREATE TABLE offerings (
8
state VARCHAR NOT NULL CHECK (state in ('no_agreement', 'pending',
9
'enabled', 'disabled'))
10
DEFAULT 'no_agreement',
11
admin BOOLEAN NOT NULL DEFAULT false,
12
unixid INT UNIQUE DEFAULT nextval('login_unixid_seq') NOT NULL,
13
nick VARCHAR NOT NULL,
19
fullname VARCHAR NOT NULL,
20
studentid VARCHAR, -- may be null
27
CREATE TABLE subject (
28
subjectid SERIAL PRIMARY KEY NOT NULL,
29
subj_code VARCHAR UNIQUE NOT NULL,
30
subj_name VARCHAR NOT NULL,
31
subj_short_name VARCHAR UNIQUE NOT NULL,
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
CREATE TABLE offering (
12
45
offeringid SERIAL PRIMARY KEY NOT NULL,
13
subj_name VARCHAR NOT NULL,
14
subj_code VARCHAR NOT NULL,
15
year CHAR(4) NOT NULL,
19
DROP TABLE groups CASCADE;
21
groupnm VARCHAR NOT NULL,
46
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)
53
-- Projects and groups
54
-- -------------------
56
CREATE TABLE project_set (
57
projectsetid SERIAL PRIMARY KEY NOT NULL,
58
offeringid INTEGER REFERENCES offering (offeringid) NOT NULL,
59
max_students_per_group INTEGER NOT NULL DEFAULT 4
62
CREATE TABLE project (
63
projectid SERIAL PRIMARY KEY NOT NULL,
66
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
70
CREATE TABLE project_group (
71
groupnm VARCHAR NOT NULL,
22
72
groupid SERIAL PRIMARY KEY NOT NULL,
23
offeringid INT4 REFERENCES offerings (offeringid),
73
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
25
UNIQUE (offeringid, groupnm)
75
createdby INT4 REFERENCES login (loginid) NOT NULL,
76
epoch TIMESTAMP NOT NULL,
77
UNIQUE (projectsetid, groupnm)
28
DROP TABLE group_invitations CASCADE;
29
CREATE TABLE group_invitations (
30
loginid INT4 REFERENCES users (loginid),
31
groupid INT4 REFERENCES groups (groupid),
80
CREATE OR REPLACE FUNCTION check_group_namespacing_insertupdate()
85
SELECT offeringid INTO oid FROM project_set WHERE project_set.projectsetid = NEW.projectsetid;
86
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;
88
RAISE EXCEPTION ''a project group named % already exists in offering ID %'', NEW.groupnm, oid;
94
CREATE TRIGGER check_group_namespacing
95
BEFORE INSERT OR UPDATE ON project_group
96
FOR EACH ROW EXECUTE PROCEDURE check_group_namespacing_insertupdate();
98
CREATE TABLE group_invitation (
99
loginid INT4 REFERENCES login (loginid) NOT NULL,
100
groupid INT4 REFERENCES project_group (groupid) NOT NULL,
101
inviter INT4 REFERENCES login (loginid) NOT NULL,
102
invited TIMESTAMP NOT NULL,
32
104
UNIQUE (loginid,groupid)
35
DROP TABLE group_members CASCADE;
36
CREATE TABLE group_members (
37
loginid INT4 REFERENCES users (loginid),
38
groupid INT4 REFERENCES groups (groupid),
39
projectid INT4 REFERENCES projects (projectid),
40
UNIQUE (loginid,projectid),
107
CREATE TABLE group_member (
108
loginid INT4 REFERENCES login (loginid),
109
groupid INT4 REFERENCES project_group (groupid),
41
110
PRIMARY KEY (loginid,groupid)
44
DROP TABLE enrolment CASCADE;
45
113
CREATE TABLE enrolment (
46
loginid INT4 REFERENCES users (loginid),
47
offeringid INT4 REFERENCES offerings (offeringid),
114
loginid INT4 REFERENCES login (loginid),
115
offeringid INT4 REFERENCES offering (offeringid),
116
role TEXT NOT NULL CHECK (role IN ('student', 'tutor',
117
'lecturer')) DEFAULT 'student',
119
special_result VARCHAR,
121
special_supp_result VARCHAR,
123
active BOOL NOT NULL DEFAULT true,
51
124
PRIMARY KEY (loginid,offeringid)
54
DROP TABLE roles CASCADE;
56
loginid INT4 PRIMARY KEY REFERENCES users (loginid),
60
DROP TABLE projects CASCADE;
61
CREATE TABLE projects (
62
projectid SERIAL PRIMARY KEY NOT NULL,
65
offeringid INT4 REFERENCES offerings (offeringid) NOT NULL,
69
DROP TABLE project_extension CASCADE;
127
CREATE TABLE assessed (
128
assessedid SERIAL PRIMARY KEY NOT NULL,
129
loginid INT4 REFERENCES login (loginid),
130
groupid INT4 REFERENCES project_group (groupid),
131
projectid INT4 REFERENCES project (projectid) NOT NULL,
132
-- exactly one of loginid and groupid must be non-null
133
CHECK ((loginid IS NOT NULL AND groupid IS NULL)
134
OR (loginid IS NULL AND groupid IS NOT NULL))
70
137
CREATE TABLE project_extension (
71
loginid INT4 REFERENCES users (loginid),
72
groupid INT4 REFERENCES groups (groupid),
73
projectid INT4 REFERENCES projects (projectid) NOT NULL,
138
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
74
139
deadline TIMESTAMP NOT NULL,
75
approver INT4 REFERENCES users (loginid) NOT NULL,
77
-- exactly one of loginid and groupid must be non-null
78
CHECK ((loginid IS NOT NULL AND groupid IS NULL)
79
OR (loginid IS NULL AND groupid IS NOT NULL))
82
DROP TABLE project_mark CASCADE;
140
approver INT4 REFERENCES login (loginid) NOT NULL,
144
CREATE TABLE project_submission (
145
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
146
path VARCHAR NOT NULL,
147
revision INT4 NOT NULL
83
150
CREATE TABLE project_mark (
84
loginid INT4 REFERENCES users (loginid),
85
groupid INT4 REFERENCES groups (groupid),
86
projectid INT4 REFERENCES projects (projectid) NOT NULL,
151
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
88
marker INT4 REFERENCES users (loginid) NOT NULL,
153
marker INT4 REFERENCES login (loginid) NOT NULL,
93
-- exactly one of loginid and groupid must be non-null
94
CHECK ((loginid IS NOT NULL AND groupid IS NULL)
95
OR (loginid IS NULL AND groupid IS NOT NULL))
98
DROP TABLE problem CASCADE;
99
CREATE TABLE problem (
100
problemid SERIAL PRIMARY KEY NOT NULL,
104
DROP TABLE problem_tags CASCADE;
105
CREATE TABLE problem_tags (
106
problemid INT4 REFERENCES tutorial_problem (problemid),
107
tag VARCHAR NOT NULL,
108
added_by INT4 REFERENCES users (loginid) NOT NULL,
109
date TIMESTAMP NOT NULL,
110
PRIMARY KEY (problemid,added_by,tag)
113
DROP TABLE problem_test_case CASCADE;
114
CREATE TABLE problem_test_case (
115
problemid INT4 REFERENCES problem (problemid) NOT NULL,
116
testcaseid SERIAL UNIQUE NOT NULL,
119
visibility VARCHAR CHECK (visibility in ('public', 'protected', 'private'))
122
DROP TABLE problem_test_case_tags CASCADE;
123
CREATE TABLE problem_test_case_tags (
124
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
125
tag VARCHAR NOT NULL,
127
added_by INT4 REFERENCES users (loginid) NOT NULL,
128
date TIMESTAMP NOT NULL,
129
PRIMARY KEY (testcaseid,added_by,tag)
132
DROP TABLE problem_attempt CASCADE;
133
CREATE TABLE problem_attempt (
134
problemid INT4 REFERENCES problem (problemid) NOT NULL,
135
loginid INT4 REFERENCES users (loginid) NOT NULL,
136
date TIMESTAMP NOT NULL,
137
attempt VARCHAR NOT NULL,
162
CREATE TABLE exercise (
163
identifier TEXT PRIMARY KEY,
172
CREATE TABLE worksheet (
173
worksheetid SERIAL PRIMARY KEY,
174
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
175
identifier TEXT NOT NULL,
178
assessable BOOLEAN NOT NULL,
179
seq_no INT4 NOT NULL,
180
format TEXT NOT NUll,
181
UNIQUE (offeringid, identifier)
184
CREATE TABLE worksheet_exercise (
185
ws_ex_id SERIAL PRIMARY KEY,
186
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
187
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
188
seq_no INT4 NOT NULL,
189
active BOOLEAN NOT NULL DEFAULT true,
190
optional BOOLEAN NOT NULL,
191
UNIQUE (worksheetid, exerciseid)
194
CREATE TABLE exercise_attempt (
195
loginid INT4 REFERENCES login (loginid) NOT NULL,
196
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
197
date TIMESTAMP NOT NULL,
198
attempt TEXT NOT NULL,
138
199
complete BOOLEAN NOT NULL,
139
PRIMARY KEY (problemid,loginid,date)
200
active BOOLEAN NOT NULL DEFAULT true,
201
PRIMARY KEY (loginid, ws_ex_id, date)
142
DROP INDEX problem_attempt_index;
143
CREATE INDEX problem_attempt_index ON problem_attempt (problemid, loginid);
145
DROP TABLE problem_attempt_breakdown CASCADE;
146
CREATE TABLE problem_attempt_breakdown (
147
problemid INT4 REFERENCES problem (problemid) NOT NULL,
148
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
149
loginid INT4 REFERENCES users (loginid) NOT NULL,
204
CREATE TABLE exercise_save (
205
loginid INT4 REFERENCES login (loginid) NOT NULL,
206
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
150
207
date TIMESTAMP NOT NULL,
154
DROP TABLE problem_prerequisites CASCADE;
155
CREATE TABLE problem_prerequisites (
156
parent INT4 REFERENCES problem (problemid) NOT NULL,
157
child INT4 REFERENCES problem (problemid) NOT NULL,
158
PRIMARY KEY (parent,child)
209
PRIMARY KEY (loginid, ws_ex_id)
212
CREATE TABLE test_suite (
213
suiteid SERIAL PRIMARY KEY,
214
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
221
CREATE TABLE test_case (
222
testid SERIAL PRIMARY KEY,
223
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
230
CREATE TABLE suite_variable (
231
varid SERIAL PRIMARY KEY,
232
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
235
var_type TEXT NOT NULL,
239
CREATE TABLE test_case_part (
240
partid SERIAL PRIMARY KEY,
241
testid INT4 REFERENCES test_case (testid) NOT NULL,
242
part_type TEXT NOT NULL,