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 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,
72
groupid SERIAL PRIMARY KEY NOT NULL,
73
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
75
createdby INT4 REFERENCES login (loginid) NOT NULL,
76
epoch TIMESTAMP NOT NULL,
77
UNIQUE (projectsetid, groupnm)
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,
104
UNIQUE (loginid,groupid)
107
CREATE TABLE group_member (
108
loginid INT4 REFERENCES login (loginid),
109
groupid INT4 REFERENCES project_group (groupid),
110
PRIMARY KEY (loginid,groupid)
25
113
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');
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,
124
PRIMARY KEY (loginid,offeringid)
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))
137
CREATE TABLE project_extension (
138
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
139
deadline TIMESTAMP NOT NULL,
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
150
CREATE TABLE project_mark (
151
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
153
marker INT4 REFERENCES login (loginid) 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,
199
complete BOOLEAN NOT NULL,
200
active BOOLEAN NOT NULL DEFAULT true,
201
PRIMARY KEY (loginid, ws_ex_id, date)
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,
207
date TIMESTAMP NOT NULL,
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,