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
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
37
CREATE TABLE project (
38
projectid SERIAL PRIMARY KEY NOT NULL,
41
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
45
CREATE TABLE project_group (
46
groupnm VARCHAR NOT NULL,
47
groupid SERIAL PRIMARY KEY NOT NULL,
48
offeringid INT4 REFERENCES offering (offeringid),
50
createdby INT4 REFERENCES login (loginid) NOT NULL,
51
epoch TIMESTAMP NOT NULL,
52
UNIQUE (offeringid, groupnm)
55
CREATE TABLE group_invitation (
56
loginid INT4 REFERENCES login (loginid) NOT NULL,
57
groupid INT4 REFERENCES project_group (groupid) NOT NULL,
58
inviter INT4 REFERENCES login (loginid) NOT NULL,
59
invited TIMESTAMP NOT NULL,
61
UNIQUE (loginid,groupid)
64
CREATE TABLE group_member (
65
loginid INT4 REFERENCES login (loginid),
66
groupid INT4 REFERENCES project_group (groupid),
67
projectid INT4 REFERENCES project (projectid),
68
UNIQUE (loginid,projectid),
69
PRIMARY KEY (loginid,groupid)
25
72
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');
73
loginid INT4 REFERENCES login (loginid),
74
offeringid INT4 REFERENCES offering (offeringid),
76
special_result VARCHAR,
78
special_supp_result VARCHAR,
80
PRIMARY KEY (loginid,offeringid)
83
CREATE TABLE assessed (
84
assessedid SERIAL PRIMARY KEY NOT NULL,
85
loginid INT4 REFERENCES login (loginid),
86
groupid INT4 REFERENCES project_group (groupid),
87
-- exactly one of loginid and groupid must be non-null
88
CHECK ((loginid IS NOT NULL AND groupid IS NULL)
89
OR (loginid IS NULL AND groupid IS NOT NULL))
92
CREATE TABLE project_extension (
93
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
94
projectid INT4 REFERENCES project (projectid) NOT NULL,
95
deadline TIMESTAMP NOT NULL,
96
approver INT4 REFERENCES login (loginid) NOT NULL,
100
CREATE TABLE project_submission (
101
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
102
projectid INT4 REFERENCES project (projectid) NOT NULL,
103
path VARCHAR NOT NULL,
104
revision INT4 NOT NULL
107
CREATE TABLE project_mark (
108
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
109
projectid INT4 REFERENCES project (projectid) NOT NULL,
111
marker INT4 REFERENCES login (loginid) NOT NULL,
118
CREATE TABLE problem (
119
problemid SERIAL PRIMARY KEY NOT NULL,
120
identifier VARCHAR UNIQUE NOT NULL,
124
CREATE TABLE worksheet (
125
worksheetid SERIAL PRIMARY KEY NOT NULL,
126
subject VARCHAR NOT NULL,
127
identifier VARCHAR NOT NULL,
130
UNIQUE (subject, identifier)
133
CREATE TABLE worksheet_problem (
134
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
135
problemid INT4 REFERENCES problem (problemid) NOT NULL,
137
PRIMARY KEY (worksheetid, problemid)
140
CREATE TABLE problem_tag (
141
problemid INT4 REFERENCES problem (problemid),
142
tag VARCHAR NOT NULL,
144
standard BOOLEAN NOT NULL,
145
added_by INT4 REFERENCES login (loginid) NOT NULL,
146
date TIMESTAMP NOT NULL,
147
PRIMARY KEY (problemid,added_by,tag)
150
CREATE TABLE problem_test_case (
151
problemid INT4 REFERENCES problem (problemid) NOT NULL,
152
testcaseid SERIAL UNIQUE NOT NULL,
155
visibility VARCHAR CHECK (visibility in ('public', 'protected', 'private'))
158
CREATE TABLE problem_test_case_tag (
159
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
160
tag VARCHAR NOT NULL,
162
standard BOOLEAN NOT NULL,
163
added_by INT4 REFERENCES login (loginid) NOT NULL,
164
date TIMESTAMP NOT NULL,
165
PRIMARY KEY (testcaseid,added_by,tag)
168
CREATE TABLE problem_attempt (
169
problemid INT4 REFERENCES problem (problemid) NOT NULL,
170
loginid INT4 REFERENCES login (loginid) NOT NULL,
171
date TIMESTAMP NOT NULL,
172
attempt VARCHAR NOT NULL,
173
complete BOOLEAN NOT NULL,
174
PRIMARY KEY (problemid,loginid,date)
177
CREATE TABLE problem_save (
178
problemid INT4 REFERENCES problem (problemid) NOT NULL,
179
loginid INT4 REFERENCES login (loginid) NOT NULL,
180
date TIMESTAMP NOT NULL,
181
text VARCHAR NOT NULL,
182
PRIMARY KEY (problemid,loginid)
185
CREATE INDEX problem_attempt_index ON problem_attempt (problemid, loginid);
187
CREATE TABLE problem_attempt_breakdown (
188
problemid INT4 REFERENCES problem (problemid) NOT NULL,
189
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
190
loginid INT4 REFERENCES login (loginid) NOT NULL,
191
date TIMESTAMP NOT NULL,
195
CREATE TABLE problem_prerequisite (
196
parent INT4 REFERENCES problem (problemid) NOT NULL,
197
child INT4 REFERENCES problem (problemid) NOT NULL,
198
PRIMARY KEY (parent,child)