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
25
CREATE TABLE subject (
26
subjectid SERIAL PRIMARY KEY NOT NULL,
27
subj_code VARCHAR UNIQUE NOT NULL,
28
subj_name VARCHAR NOT NULL,
29
subj_short_name VARCHAR UNIQUE NOT 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
CREATE TABLE offering (
43
offeringid SERIAL PRIMARY KEY NOT NULL,
44
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
58
CREATE TABLE project (
59
projectid SERIAL PRIMARY KEY NOT NULL,
60
short_name TEXT NOT NULL,
64
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
68
CREATE OR REPLACE FUNCTION check_project_namespacing_insertupdate()
73
IF TG_OP = ''UPDATE'' THEN
74
IF NEW.projectsetid = OLD.projectsetid AND NEW.short_name = OLD.short_name THEN
78
SELECT offeringid INTO oid FROM project_set WHERE project_set.projectsetid = NEW.projectsetid;
79
PERFORM 1 FROM project, project_set
80
WHERE project_set.offeringid = oid AND
81
project.projectsetid = project_set.projectsetid AND
82
project.short_name = NEW.short_name;
84
RAISE EXCEPTION ''a project named % already exists in offering ID %'', NEW.short_name, oid;
90
CREATE TRIGGER check_project_namespacing
91
BEFORE INSERT OR UPDATE ON project
92
FOR EACH ROW EXECUTE PROCEDURE check_project_namespacing_insertupdate();
94
CREATE TABLE project_group (
95
groupnm VARCHAR NOT NULL,
96
groupid SERIAL PRIMARY KEY NOT NULL,
97
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
99
createdby INT4 REFERENCES login (loginid) NOT NULL,
100
epoch TIMESTAMP NOT NULL,
101
UNIQUE (projectsetid, groupnm)
104
CREATE OR REPLACE FUNCTION check_group_namespacing_insertupdate()
109
SELECT offeringid INTO oid FROM project_set WHERE project_set.projectsetid = NEW.projectsetid;
110
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;
112
RAISE EXCEPTION ''a project group named % already exists in offering ID %'', NEW.groupnm, oid;
116
' LANGUAGE 'plpgsql';
118
CREATE TRIGGER check_group_namespacing
119
BEFORE INSERT OR UPDATE ON project_group
120
FOR EACH ROW EXECUTE PROCEDURE check_group_namespacing_insertupdate();
122
CREATE TABLE group_invitation (
123
loginid INT4 REFERENCES login (loginid) NOT NULL,
124
groupid INT4 REFERENCES project_group (groupid) NOT NULL,
125
inviter INT4 REFERENCES login (loginid) NOT NULL,
126
invited TIMESTAMP NOT NULL,
128
UNIQUE (loginid,groupid)
131
CREATE TABLE group_member (
132
loginid INT4 REFERENCES login (loginid),
133
groupid INT4 REFERENCES project_group (groupid),
134
PRIMARY KEY (loginid,groupid)
1
-- We need a users database to do authorization, manage groups, &c
6
DROP TABLE group_members;
11
login varchar(80) PRIMARY KEY, -- login id
16
groupid varchar(18) PRIMARY KEY, -- group name Y^4-S^9-G^3
17
nick varchar(80), -- group nickname
18
subject varchar(9), -- subject code
19
year varchar(4) -- when
22
CREATE TABLE group_members (
23
login varchar(80) REFERENCES users (login),
24
groupid varchar(18) REFERENCES groups (groupid)
137
27
CREATE TABLE enrolment (
138
loginid INT4 REFERENCES login (loginid),
139
offeringid INT4 REFERENCES offering (offeringid),
140
role TEXT NOT NULL CHECK (role IN ('student', 'tutor',
141
'lecturer')) DEFAULT 'student',
143
special_result VARCHAR,
145
special_supp_result VARCHAR,
147
active BOOL NOT NULL DEFAULT true,
148
PRIMARY KEY (loginid,offeringid)
151
CREATE TABLE assessed (
152
assessedid SERIAL PRIMARY KEY NOT NULL,
153
loginid INT4 REFERENCES login (loginid),
154
groupid INT4 REFERENCES project_group (groupid),
155
projectid INT4 REFERENCES project (projectid) NOT NULL,
156
-- exactly one of loginid and groupid must be non-null
157
CHECK ((loginid IS NOT NULL AND groupid IS NULL)
158
OR (loginid IS NULL AND groupid IS NOT NULL))
161
CREATE TABLE project_extension (
162
extensionid SERIAL PRIMARY KEY,
163
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
164
deadline TIMESTAMP NOT NULL,
165
approver INT4 REFERENCES login (loginid) NOT NULL,
169
CREATE TABLE project_submission (
170
submissionid SERIAL PRIMARY KEY,
171
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
172
path VARCHAR NOT NULL,
173
revision INT4 NOT NULL,
174
date_submitted TIMESTAMP NOT NULL,
175
submitter INT4 REFERENCES login (loginid) NOT NULL
178
CREATE TABLE project_mark (
179
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
181
marker INT4 REFERENCES login (loginid) NOT NULL,
188
CREATE TABLE exercise (
189
identifier TEXT PRIMARY KEY,
198
CREATE TABLE worksheet (
199
worksheetid SERIAL PRIMARY KEY,
200
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
201
identifier TEXT NOT NULL,
204
assessable BOOLEAN NOT NULL,
205
seq_no INT4 NOT NULL,
206
format TEXT NOT NUll,
207
UNIQUE (offeringid, identifier)
210
CREATE TABLE worksheet_exercise (
211
ws_ex_id SERIAL PRIMARY KEY,
212
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
213
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
214
seq_no INT4 NOT NULL,
215
active BOOLEAN NOT NULL DEFAULT true,
216
optional BOOLEAN NOT NULL,
217
UNIQUE (worksheetid, exerciseid)
220
CREATE TABLE exercise_attempt (
221
loginid INT4 REFERENCES login (loginid) NOT NULL,
222
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
223
date TIMESTAMP NOT NULL,
224
attempt TEXT NOT NULL,
225
complete BOOLEAN NOT NULL,
226
active BOOLEAN NOT NULL DEFAULT true,
227
PRIMARY KEY (loginid, ws_ex_id, date)
230
CREATE TABLE exercise_save (
231
loginid INT4 REFERENCES login (loginid) NOT NULL,
232
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
233
date TIMESTAMP NOT NULL,
235
PRIMARY KEY (loginid, ws_ex_id)
238
CREATE TABLE test_suite (
239
suiteid SERIAL PRIMARY KEY,
240
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
247
CREATE TABLE test_case (
248
testid SERIAL PRIMARY KEY,
249
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
256
CREATE TABLE suite_variable (
257
varid SERIAL PRIMARY KEY,
258
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
261
var_type TEXT NOT NULL,
265
CREATE TABLE test_case_part (
266
partid SERIAL PRIMARY KEY,
267
testid INT4 REFERENCES test_case (testid) NOT NULL,
268
part_type TEXT NOT NULL,
28
login varchar(80) REFERENCES users (login),
34
login varchar(80) REFERENCES users (login),
38
INSERT INTO users (login,nick) values ('conway', 'Tom');
39
INSERT INTO roles (login,role) values ('conway', 'student');
40
INSERT INTO users (login,nick) values ('apeel', 'Andrew');
41
INSERT INTO roles (login,role) values ('apeel', 'student');
42
INSERT INTO users (login,nick) values ('mgiuca', 'Matt');
43
INSERT INTO roles (login,role) values ('mgiuca', 'tutor');
44
INSERT INTO users (login,nick) values ('sb', 'Steven');
45
INSERT INTO roles (login,role) values ('sb', 'lecturer');
46
INSERT INTO users (login,nick) values ('mpp', 'Mike');
47
INSERT INTO roles (login,role) values ('mpp', 'student');
48
INSERT INTO users (login,nick) values ('ivo', 'Ivo');
49
INSERT INTO roles (login,role) values ('ivo', 'admin');
51
INSERT INTO groups (groupid, nick, subject, year) values ('2007-INFO10001-321', 'Purple Alert', 'INFO10001', '2008');
52
INSERT INTO groups (groupid, nick, subject, year) values ('2007-INFO10001-322', 'Blind Illuminati', 'INFO10001', '2008');
54
INSERT INTO group_members (login,groupid) values ('conway', '2007-INFO10001-321');
55
INSERT INTO group_members (login,groupid) values ('apeel', '2007-INFO10001-321');
56
INSERT INTO group_members (login,groupid) values ('mgiuca', '2007-INFO10001-321');
57
INSERT INTO group_members (login,groupid) values ('sb', '2007-INFO10001-321');
58
INSERT INTO group_members (login,groupid) values ('mpp', '2007-INFO10001-322');
59
INSERT INTO group_members (login,groupid) values ('ivo', '2007-INFO10001-322');
61
INSERT INTO enrolment (login,subject,year) values ('conway' , 'INFO10001', '2008');
62
INSERT INTO enrolment (login,subject,year) values ('apeel' , 'INFO10001', '2008');
63
INSERT INTO enrolment (login,subject,year) values ('mgiuca' , 'INFO10001', '2008');
64
INSERT INTO enrolment (login,subject,year) values ('sb' , 'INFO10001', '2008');
65
INSERT INTO enrolment (login,subject,year) values ('mpp' , 'INFO10001', '2008');
66
INSERT INTO enrolment (login,subject,year) values ('ivo' , 'INFO10001', '2008');