4
DROP TABLE group_members;
9
login varchar(80) PRIMARY KEY, -- login id
14
groupid varchar(18) PRIMARY KEY, -- group name Y^4-S^9-G^3
15
nick varchar(80), -- group nickname
16
subject varchar(9), -- subject code
17
year varchar(4) -- when
20
CREATE TABLE group_members (
21
login varchar(80) REFERENCES users (login),
22
groupid varchar(18) REFERENCES groups (groupid)
2
CREATE SEQUENCE login_unixid_seq MINVALUE 1000 MAXVALUE 29999 START WITH 5000;
5
loginid SERIAL PRIMARY KEY NOT NULL,
6
login VARCHAR UNIQUE NOT NULL,
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 (
45
offeringid SERIAL PRIMARY KEY 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
62
CREATE TABLE project (
63
projectid SERIAL PRIMARY KEY NOT NULL,
64
short_name TEXT NOT NULL,
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();
98
CREATE TABLE project_group (
99
groupnm VARCHAR NOT NULL,
100
groupid SERIAL PRIMARY KEY NOT NULL,
101
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
103
createdby INT4 REFERENCES login (loginid) NOT NULL,
104
epoch TIMESTAMP NOT NULL,
105
UNIQUE (projectsetid, groupnm)
108
CREATE OR REPLACE FUNCTION check_group_namespacing_insertupdate()
113
SELECT offeringid INTO oid FROM project_set WHERE project_set.projectsetid = NEW.projectsetid;
114
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;
116
RAISE EXCEPTION ''a project group named % already exists in offering ID %'', NEW.groupnm, oid;
120
' LANGUAGE 'plpgsql';
122
CREATE TRIGGER check_group_namespacing
123
BEFORE INSERT OR UPDATE ON project_group
124
FOR EACH ROW EXECUTE PROCEDURE check_group_namespacing_insertupdate();
126
CREATE TABLE group_invitation (
127
loginid INT4 REFERENCES login (loginid) NOT NULL,
128
groupid INT4 REFERENCES project_group (groupid) NOT NULL,
129
inviter INT4 REFERENCES login (loginid) NOT NULL,
130
invited TIMESTAMP NOT NULL,
132
UNIQUE (loginid,groupid)
135
CREATE TABLE group_member (
136
loginid INT4 REFERENCES login (loginid),
137
groupid INT4 REFERENCES project_group (groupid),
138
PRIMARY KEY (loginid,groupid)
25
141
CREATE TABLE enrolment (
26
login varchar(80) REFERENCES users (login),
32
login varchar(80) REFERENCES users (login),
36
INSERT INTO users (login,nick) values ('conway', 'Tom');
37
INSERT INTO roles (login,role) values ('conway', 'student');
38
INSERT INTO users (login,nick) values ('apeel', 'Andrew');
39
INSERT INTO roles (login,role) values ('apeel', 'student');
40
INSERT INTO users (login,nick) values ('mgiuca', 'Matt');
41
INSERT INTO roles (login,role) values ('mgiuca', 'tutor');
42
INSERT INTO users (login,nick) values ('sb', 'Steven');
43
INSERT INTO roles (login,role) values ('sb', 'lecturer');
44
INSERT INTO users (login,nick) values ('mpp', 'Mike');
45
INSERT INTO roles (login,role) values ('mpp', 'student');
46
INSERT INTO users (login,nick) values ('ivo', 'Ivo');
47
INSERT INTO roles (login,role) values ('ivo', 'admin');
49
INSERT INTO groups (groupid, nick, subject, year) values ('2007-INFO10001-321', 'Purple Alert', 'INFO10001', '2008');
50
INSERT INTO groups (groupid, nick, subject, year) values ('2007-INFO10001-322', 'Blind Illuminati', 'INFO10001', '2008');
52
INSERT INTO group_members (login,groupid) values ('conway', '2007-INFO10001-321');
53
INSERT INTO group_members (login,groupid) values ('apeel', '2007-INFO10001-321');
54
INSERT INTO group_members (login,groupid) values ('mgiuca', '2007-INFO10001-321');
55
INSERT INTO group_members (login,groupid) values ('sb', '2007-INFO10001-321');
56
INSERT INTO group_members (login,groupid) values ('mpp', '2007-INFO10001-322');
57
INSERT INTO group_members (login,groupid) values ('ivo', '2007-INFO10001-322');
59
INSERT INTO enrolment (login,subject,year) values ('conway' , 'INFO10001', '2008');
60
INSERT INTO enrolment (login,subject,year) values ('apeel' , 'INFO10001', '2008');
61
INSERT INTO enrolment (login,subject,year) values ('mgiuca' , 'INFO10001', '2008');
62
INSERT INTO enrolment (login,subject,year) values ('sb' , 'INFO10001', '2008');
63
INSERT INTO enrolment (login,subject,year) values ('mpp' , 'INFO10001', '2008');
64
INSERT INTO enrolment (login,subject,year) values ('ivo' , 'INFO10001', '2008');
142
loginid INT4 REFERENCES login (loginid),
143
offeringid INT4 REFERENCES offering (offeringid),
144
role TEXT NOT NULL CHECK (role IN ('student', 'tutor',
145
'lecturer')) DEFAULT 'student',
147
special_result VARCHAR,
149
special_supp_result VARCHAR,
151
active BOOL NOT NULL DEFAULT true,
152
PRIMARY KEY (loginid,offeringid)
155
CREATE TABLE assessed (
156
assessedid SERIAL PRIMARY KEY NOT NULL,
157
loginid INT4 REFERENCES login (loginid),
158
groupid INT4 REFERENCES project_group (groupid),
159
projectid INT4 REFERENCES project (projectid) NOT NULL,
160
-- exactly one of loginid and groupid must be non-null
161
CHECK ((loginid IS NOT NULL AND groupid IS NULL)
162
OR (loginid IS NULL AND groupid IS NOT NULL))
165
CREATE TABLE project_extension (
166
extensionid SERIAL PRIMARY KEY,
167
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
168
deadline TIMESTAMP NOT NULL,
169
approver INT4 REFERENCES login (loginid) NOT NULL,
173
CREATE TABLE project_submission (
174
submissionid SERIAL PRIMARY KEY,
175
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
176
path VARCHAR NOT NULL,
177
revision INT4 NOT NULL,
178
date_submitted TIMESTAMP NOT NULL,
179
submitter INT4 REFERENCES login (loginid) NOT NULL
182
CREATE TABLE project_mark (
183
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
185
marker INT4 REFERENCES login (loginid) NOT NULL,
194
CREATE TABLE exercise (
195
identifier TEXT PRIMARY KEY,
204
CREATE TABLE worksheet (
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 (
227
loginid INT4 REFERENCES login (loginid) NOT NULL,
228
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
229
date TIMESTAMP NOT NULL,
230
attempt TEXT NOT NULL,
231
complete BOOLEAN NOT NULL,
232
active BOOLEAN NOT NULL DEFAULT true,
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,