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
rolenm VARCHAR NOT NULL CHECK (rolenm in ('anyone', 'student',
13
'lecturer', 'admin')),
14
unixid INT UNIQUE DEFAULT nextval('login_unixid_seq') NOT NULL,
15
nick VARCHAR NOT NULL,
21
fullname VARCHAR NOT NULL,
22
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,
40
UNIQUE (year, semester)
43
CREATE OR REPLACE FUNCTION deactivate_semester_enrolments_update()
46
IF OLD.active = true AND NEW.active = false THEN
47
UPDATE enrolment SET active=false WHERE offeringid IN (
48
SELECT offeringid FROM offering WHERE offering.semesterid = NEW.semesterid);
54
CREATE TRIGGER deactivate_semester_enrolments
55
AFTER UPDATE ON semester
56
FOR EACH ROW EXECUTE PROCEDURE deactivate_semester_enrolments_update();
58
CREATE TABLE offering (
59
offeringid SERIAL PRIMARY KEY NOT NULL,
60
subject INT4 REFERENCES subject (subjectid) NOT NULL,
61
semesterid INTEGER REFERENCES semester (semesterid) NOT NULL,
62
groups_student_permissions VARCHAR NOT NULL DEFAULT 'none',
63
CHECK (groups_student_permissions in ('none', 'invite', 'create')),
64
UNIQUE (subject, semesterid)
68
CREATE TABLE project_set (
69
projectsetid SERIAL PRIMARY KEY NOT NULL,
70
offeringid INTEGER REFERENCES offering (offeringid) NOT NULL,
71
max_students_per_group INTEGER NOT NULL DEFAULT 4
74
CREATE TABLE project (
75
projectid SERIAL PRIMARY KEY NOT NULL,
78
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
82
CREATE TABLE project_group (
83
groupnm VARCHAR NOT NULL,
84
groupid SERIAL PRIMARY KEY NOT NULL,
85
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
87
createdby INT4 REFERENCES login (loginid) NOT NULL,
88
epoch TIMESTAMP NOT NULL,
89
UNIQUE (projectsetid, groupnm)
92
CREATE OR REPLACE FUNCTION check_group_namespacing_insertupdate()
97
SELECT offeringid INTO oid FROM project_set WHERE project_set.projectsetid = NEW.projectsetid;
98
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;
100
RAISE EXCEPTION ''a project group named % already exists in offering ID %'', NEW.groupnm, oid;
104
' LANGUAGE 'plpgsql';
106
CREATE TRIGGER check_group_namespacing
107
BEFORE INSERT OR UPDATE ON project_group
108
FOR EACH ROW EXECUTE PROCEDURE check_group_namespacing_insertupdate();
110
CREATE TABLE group_invitation (
111
loginid INT4 REFERENCES login (loginid) NOT NULL,
112
groupid INT4 REFERENCES project_group (groupid) NOT NULL,
113
inviter INT4 REFERENCES login (loginid) NOT NULL,
114
invited TIMESTAMP NOT NULL,
116
UNIQUE (loginid,groupid)
119
CREATE TABLE group_member (
120
loginid INT4 REFERENCES login (loginid),
121
groupid INT4 REFERENCES project_group (groupid),
122
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)
125
27
CREATE TABLE enrolment (
126
loginid INT4 REFERENCES login (loginid),
127
offeringid INT4 REFERENCES offering (offeringid),
129
special_result VARCHAR,
131
special_supp_result VARCHAR,
133
active BOOL NOT NULL DEFAULT true,
134
PRIMARY KEY (loginid,offeringid)
137
CREATE OR REPLACE FUNCTION confirm_active_semester_insertupdate()
142
SELECT semester.active INTO active FROM offering, semester WHERE offeringid=NEW.offeringid AND semester.semesterid = offering.semesterid;
143
IF NOT active AND NEW.active = true THEN
144
RAISE EXCEPTION ''cannot have active enrolment for % in offering %, as the semester is inactive'', NEW.loginid, NEW.offeringid;
148
' LANGUAGE 'plpgsql';
150
CREATE TRIGGER confirm_active_semester
151
BEFORE INSERT OR UPDATE ON enrolment
152
FOR EACH ROW EXECUTE PROCEDURE confirm_active_semester_insertupdate();
154
CREATE TABLE assessed (
155
assessedid SERIAL PRIMARY KEY NOT NULL,
156
loginid INT4 REFERENCES login (loginid),
157
groupid INT4 REFERENCES project_group (groupid),
158
projectid INT4 REFERENCES project (projectid) NOT NULL,
159
-- exactly one of loginid and groupid must be non-null
160
CHECK ((loginid IS NOT NULL AND groupid IS NULL)
161
OR (loginid IS NULL AND groupid IS NOT NULL))
164
CREATE TABLE project_extension (
165
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
166
deadline TIMESTAMP NOT NULL,
167
approver INT4 REFERENCES login (loginid) NOT NULL,
171
CREATE TABLE project_submission (
172
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
173
path VARCHAR NOT NULL,
174
revision INT4 NOT NULL
177
CREATE TABLE project_mark (
178
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
180
marker INT4 REFERENCES login (loginid) NOT NULL,
187
CREATE TABLE problem (
188
identifier TEXT PRIMARY KEY,
197
CREATE TABLE worksheet (
198
worksheetid SERIAL PRIMARY KEY,
199
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
200
identifier VARCHAR NOT NULL,
203
UNIQUE (offeringid, identifier)
206
CREATE TABLE worksheet_problem (
207
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
208
problemid TEXT REFERENCES problem (identifier) NOT NULL,
210
PRIMARY KEY (worksheetid, problemid)
213
CREATE TABLE problem_attempt (
214
problemid TEXT REFERENCES problem (identifier) NOT NULL,
215
loginid INT4 REFERENCES login (loginid) NOT NULL,
216
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
217
date TIMESTAMP NOT NULL,
218
attempt VARCHAR NOT NULL,
219
complete BOOLEAN NOT NULL,
220
active BOOLEAN NOT NULL DEFAULT true,
221
PRIMARY KEY (problemid,loginid,worksheetid,date)
224
CREATE TABLE problem_save (
225
problemid TEXT REFERENCES problem (identifier) NOT NULL,
226
loginid INT4 REFERENCES login (loginid) NOT NULL,
227
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
228
date TIMESTAMP NOT NULL,
230
PRIMARY KEY (problemid,loginid, worksheetid)
233
CREATE TABLE test_suite (
234
suiteid SERIAL PRIMARY KEY,
235
problemid TEXT REFERENCES problem (identifier) NOT NULL,
242
CREATE TABLE test_case (
243
testid SERIAL PRIMARY KEY,
244
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
251
CREATE TABLE suite_variables (
252
varid SERIAL PRIMARY KEY,
253
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
256
var_type TEXT NOT NULL,
260
CREATE TABLE test_case_parts (
261
partid SERIAL PRIMARY KEY,
262
testid INT4 REFERENCES test_case (testid) NOT NULL,
263
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');