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 NOT NULL DEFAULT 4
58
CREATE TABLE project (
59
projectid SERIAL PRIMARY KEY NOT NULL,
62
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
66
CREATE TABLE project_group (
67
groupnm VARCHAR NOT NULL,
68
groupid SERIAL PRIMARY KEY NOT NULL,
69
projectsetid INTEGER REFERENCES project_set (projectsetid) NOT NULL,
71
createdby INT4 REFERENCES login (loginid) NOT NULL,
72
epoch TIMESTAMP NOT NULL,
73
UNIQUE (projectsetid, groupnm)
76
CREATE OR REPLACE FUNCTION check_group_namespacing_insertupdate()
81
SELECT offeringid INTO oid FROM project_set WHERE project_set.projectsetid = NEW.projectsetid;
82
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;
84
RAISE EXCEPTION ''a project group named % already exists in offering ID %'', NEW.groupnm, oid;
90
CREATE TRIGGER check_group_namespacing
91
BEFORE INSERT OR UPDATE ON project_group
92
FOR EACH ROW EXECUTE PROCEDURE check_group_namespacing_insertupdate();
94
CREATE TABLE group_invitation (
95
loginid INT4 REFERENCES login (loginid) NOT NULL,
96
groupid INT4 REFERENCES project_group (groupid) NOT NULL,
97
inviter INT4 REFERENCES login (loginid) NOT NULL,
98
invited TIMESTAMP NOT NULL,
100
UNIQUE (loginid,groupid)
103
CREATE TABLE group_member (
104
loginid INT4 REFERENCES login (loginid),
105
groupid INT4 REFERENCES project_group (groupid),
106
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)
109
27
CREATE TABLE enrolment (
110
loginid INT4 REFERENCES login (loginid),
111
offeringid INT4 REFERENCES offering (offeringid),
112
role TEXT NOT NULL CHECK (role IN ('student', 'tutor',
113
'lecturer')) DEFAULT 'student',
115
special_result VARCHAR,
117
special_supp_result VARCHAR,
119
active BOOL NOT NULL DEFAULT true,
120
PRIMARY KEY (loginid,offeringid)
123
CREATE TABLE assessed (
124
assessedid SERIAL PRIMARY KEY NOT NULL,
125
loginid INT4 REFERENCES login (loginid),
126
groupid INT4 REFERENCES project_group (groupid),
127
projectid INT4 REFERENCES project (projectid) NOT NULL,
128
-- exactly one of loginid and groupid must be non-null
129
CHECK ((loginid IS NOT NULL AND groupid IS NULL)
130
OR (loginid IS NULL AND groupid IS NOT NULL))
133
CREATE TABLE project_extension (
134
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
135
deadline TIMESTAMP NOT NULL,
136
approver INT4 REFERENCES login (loginid) NOT NULL,
140
CREATE TABLE project_submission (
141
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
142
path VARCHAR NOT NULL,
143
revision INT4 NOT NULL
146
CREATE TABLE project_mark (
147
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
149
marker INT4 REFERENCES login (loginid) NOT NULL,
156
CREATE TABLE exercise (
157
identifier TEXT PRIMARY KEY,
166
CREATE TABLE worksheet (
167
worksheetid SERIAL PRIMARY KEY,
168
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
169
identifier TEXT NOT NULL,
172
assessable BOOLEAN NOT NULL,
173
seq_no INT4 NOT NULL,
174
format TEXT NOT NUll,
175
UNIQUE (offeringid, identifier)
178
CREATE TABLE worksheet_exercise (
179
ws_ex_id SERIAL PRIMARY KEY,
180
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
181
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
182
seq_no INT4 NOT NULL,
183
active BOOLEAN NOT NULL DEFAULT true,
184
optional BOOLEAN NOT NULL,
185
UNIQUE (worksheetid, exerciseid)
188
CREATE TABLE exercise_attempt (
189
loginid INT4 REFERENCES login (loginid) NOT NULL,
190
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
191
date TIMESTAMP NOT NULL,
192
attempt TEXT NOT NULL,
193
complete BOOLEAN NOT NULL,
194
active BOOLEAN NOT NULL DEFAULT true,
195
PRIMARY KEY (loginid, ws_ex_id, date)
198
CREATE TABLE exercise_save (
199
loginid INT4 REFERENCES login (loginid) NOT NULL,
200
ws_ex_id INT4 REFERENCES worksheet_exercise (ws_ex_id) NOT NULL,
201
date TIMESTAMP NOT NULL,
203
PRIMARY KEY (loginid, ws_ex_id)
206
CREATE TABLE test_suite (
207
suiteid SERIAL PRIMARY KEY,
208
exerciseid TEXT REFERENCES exercise (identifier) NOT NULL,
215
CREATE TABLE test_case (
216
testid SERIAL PRIMARY KEY,
217
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
224
CREATE TABLE suite_variable (
225
varid SERIAL PRIMARY KEY,
226
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
229
var_type TEXT NOT NULL,
233
CREATE TABLE test_case_part (
234
partid SERIAL PRIMARY KEY,
235
testid INT4 REFERENCES test_case (testid) NOT NULL,
236
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');