2
loginid SERIAL PRIMARY KEY NOT NULL,
3
login VARCHAR UNIQUE NOT NULL,
5
state VARCHAR NOT NULL CHECK (state in ('no_agreement', 'pending',
6
'enabled', 'disabled')),
7
rolenm VARCHAR NOT NULL CHECK (rolenm in ('anyone', 'student',
10
unixid INT UNIQUE NOT NULL, -- unix user id
11
nick VARCHAR NOT NULL,
17
fullname VARCHAR NOT NULL,
18
studentid VARCHAR, -- may be null
22
CREATE TABLE subject (
23
subjectid SERIAL PRIMARY KEY NOT NULL,
24
subj_code VARCHAR UNIQUE NOT NULL,
25
subj_name VARCHAR NOT NULL,
26
subj_short_name VARCHAR, -- may be null
30
CREATE TABLE offering (
31
offeringid SERIAL PRIMARY KEY NOT NULL,
32
subject INT4 REFERENCES subject (subjectid) NOT NULL,
33
year CHAR(4) NOT NULL,
34
semester CHAR(1) NOT NULL,
35
UNIQUE (subject, year, semester)
38
CREATE TABLE project (
39
projectid SERIAL PRIMARY KEY NOT NULL,
42
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
46
CREATE TABLE project_group (
47
groupnm VARCHAR NOT NULL,
48
groupid SERIAL PRIMARY KEY NOT NULL,
49
offeringid INT4 REFERENCES offering (offeringid),
51
createdby INT4 REFERENCES login (loginid) NOT NULL,
52
epoch TIMESTAMP NOT NULL,
53
UNIQUE (offeringid, groupnm)
56
CREATE TABLE group_invitation (
57
loginid INT4 REFERENCES login (loginid) NOT NULL,
58
groupid INT4 REFERENCES project_group (groupid) NOT NULL,
59
inviter INT4 REFERENCES login (loginid) NOT NULL,
60
invited TIMESTAMP NOT NULL,
62
UNIQUE (loginid,groupid)
65
CREATE TABLE group_member (
66
loginid INT4 REFERENCES login (loginid),
67
groupid INT4 REFERENCES project_group (groupid),
68
projectid INT4 REFERENCES project (projectid),
69
UNIQUE (loginid,projectid),
70
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)
73
27
CREATE TABLE enrolment (
74
loginid INT4 REFERENCES login (loginid),
75
offeringid INT4 REFERENCES offering (offeringid),
77
special_result VARCHAR,
79
special_supp_result VARCHAR,
81
PRIMARY KEY (loginid,offeringid)
84
CREATE TABLE assessed (
85
assessedid SERIAL PRIMARY KEY NOT NULL,
86
loginid INT4 REFERENCES login (loginid),
87
groupid INT4 REFERENCES project_group (groupid),
88
-- exactly one of loginid and groupid must be non-null
89
CHECK ((loginid IS NOT NULL AND groupid IS NULL)
90
OR (loginid IS NULL AND groupid IS NOT NULL))
93
CREATE TABLE project_extension (
94
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
95
projectid INT4 REFERENCES project (projectid) NOT NULL,
96
deadline TIMESTAMP NOT NULL,
97
approver INT4 REFERENCES login (loginid) NOT NULL,
101
CREATE TABLE project_submission (
102
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
103
projectid INT4 REFERENCES project (projectid) NOT NULL,
104
path VARCHAR NOT NULL,
105
revision INT4 NOT NULL
108
CREATE TABLE project_mark (
109
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
110
projectid INT4 REFERENCES project (projectid) NOT NULL,
112
marker INT4 REFERENCES login (loginid) NOT NULL,
119
CREATE TABLE problem (
120
problemid SERIAL PRIMARY KEY NOT NULL,
121
identifier VARCHAR UNIQUE NOT NULL,
125
CREATE TABLE worksheet (
126
worksheetid SERIAL PRIMARY KEY NOT NULL,
127
subject VARCHAR NOT NULL,
128
identifier VARCHAR NOT NULL,
131
UNIQUE (subject, identifier)
134
CREATE TABLE worksheet_problem (
135
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
136
problemid INT4 REFERENCES problem (problemid) NOT NULL,
138
PRIMARY KEY (worksheetid, problemid)
141
CREATE TABLE problem_tag (
142
problemid INT4 REFERENCES problem (problemid),
143
tag VARCHAR NOT NULL,
145
standard BOOLEAN NOT NULL,
146
added_by INT4 REFERENCES login (loginid) NOT NULL,
147
date TIMESTAMP NOT NULL,
148
PRIMARY KEY (problemid,added_by,tag)
151
CREATE TABLE problem_test_case (
152
problemid INT4 REFERENCES problem (problemid) NOT NULL,
153
testcaseid SERIAL UNIQUE NOT NULL,
156
visibility VARCHAR CHECK (visibility in ('public', 'protected', 'private'))
159
CREATE TABLE problem_test_case_tag (
160
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
161
tag VARCHAR NOT NULL,
163
standard BOOLEAN NOT NULL,
164
added_by INT4 REFERENCES login (loginid) NOT NULL,
165
date TIMESTAMP NOT NULL,
166
PRIMARY KEY (testcaseid,added_by,tag)
169
CREATE TABLE problem_attempt (
170
problemid INT4 REFERENCES problem (problemid) NOT NULL,
171
loginid INT4 REFERENCES login (loginid) NOT NULL,
172
date TIMESTAMP NOT NULL,
173
attempt VARCHAR NOT NULL,
174
complete BOOLEAN NOT NULL,
175
PRIMARY KEY (problemid,loginid,date)
178
CREATE TABLE problem_save (
179
problemid INT4 REFERENCES problem (problemid) NOT NULL,
180
loginid INT4 REFERENCES login (loginid) NOT NULL,
181
date TIMESTAMP NOT NULL,
182
text VARCHAR NOT NULL,
183
PRIMARY KEY (problemid,loginid)
186
CREATE INDEX problem_attempt_index ON problem_attempt (problemid, loginid);
188
CREATE TABLE problem_attempt_breakdown (
189
problemid INT4 REFERENCES problem (problemid) NOT NULL,
190
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
191
loginid INT4 REFERENCES login (loginid) NOT NULL,
192
date TIMESTAMP NOT NULL,
196
CREATE TABLE problem_prerequisite (
197
parent INT4 REFERENCES problem (problemid) NOT NULL,
198
child INT4 REFERENCES problem (problemid) NOT NULL,
199
PRIMARY KEY (parent,child)
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');