10
10
CREATE TABLE users (
11
login varchar(80) PRIMARY KEY, -- login id
11
login VARCHAR UNIQUE NOT NULL,
12
loginid SERIAL PRIMARY KEY NOT NULL,
15
studentid VARCHAR, -- may be null
15
18
CREATE TABLE groups (
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
19
group VARCHAR NOT NULL,
20
groupid SERIAL PRIMARY KEY NOT NULL,
21
offeringid INT4 REFERENCES offerings (offeringid),
23
UNIQUE (offeringid, group)
26
CREATE TABLE group_invitations (
27
loginid INT4 REFERENCES users (loginid),
28
groupid INT4 REFERENCES groups (groupid),
29
UNIQUE (loginid,groupid)
22
32
CREATE TABLE group_members (
23
login varchar(80) REFERENCES users (login),
24
groupid varchar(18) REFERENCES groups (groupid)
33
loginid INT4 REFERENCES users (loginid),
34
groupid INT4 REFERENCES groups (groupid),
35
projectid INT4 REFERENCES projects (projectid),
36
UNIQUE (loginid,projectid),
37
PRIMARY KEY (loginid,groupid)
27
40
CREATE TABLE enrolment (
28
login varchar(80) REFERENCES users (login),
41
loginid INT4 REFERENCES users (loginid),
42
offeringid INT4 REFERENCES offerings (offeringid),
46
PRIMARY KEY (loginid,offeringid)
33
49
CREATE TABLE roles (
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');
50
loginid INT4 PRIMARY KEY REFERENCES users (loginid),
54
CREATE TABLE projects (
55
projectid SERIAL PRIMARY KEY NOT NULL,
58
offeringid INT4 REFERENCES offerings (offeringid) NOT NULL,
62
CREATE TABLE project_extension (
64
projectid INT4 REFERENCES projects (projectid) NOT NULL,
65
deadline TIMESTAMP NOT NULL,
66
approver INT4 REFERENCES users (loginid) NOT NULL,
70
CREATE TABLE project_mark (
72
projectid INT4 REFERENCES projects (projectid) NOT NULL,
74
marker INT4 REFERENCES users (loginid) NOT NULL,
79
PRIMARY KEY (loginid/groupid, projectid, componentid)
82
CREATE TABLE problem (
83
problemid SERIAL PRIMARY KEY NOT NULL,
87
CREATE TABLE problem_tags (
88
problemid INT4 REFERENCES tutorial_problem (problemid),
90
added_by INT4 REFERENCES users (loginid) NOT NULL,
91
when TIMESTAMP NOT NULL,
92
PRIMARY KEY (problemid,added_by,tag)
95
CREATE TABLE problem_test_case (
96
problemid INT4 REFERENCES problem (problemid) NOT NULL,
97
testcaseid SERIAL UNIQUE NOT NULL,
100
visibility VARCHAR CHECK (visibility in ('public', 'protected', 'private'))
103
CREATE TABLE problem_test_case_tags (
104
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
105
tag VARCHAR NOT NULL,
107
added_by INT4 REFERENCES users (loginid) NOT NULL,
108
when TIMESTAMP NOT NULL,
109
PRIMARY KEY (testcaseid,added_by,tag)
112
CREATE TABLE problem_attempt (
113
problemid INT4 REFERENCES problem (problemid) NOT NULL,
114
loginid INT4 REFERENCES users (loginid) NOT NULL,
115
when TIMESTAMP NOT NULL,
116
attempt VARCHAR NOT NULL,
117
complete BOOLEAN NOT NULL,
118
PRIMARY KEY (problemid,loginid,when)
121
CREATE INDEX indexname ON problem_attempt (problemid, login);
123
CREATE TABLE problem_attempt_breakdown (
124
problemid INT4 REFERENCES problem (problemid) NOT NULL,
125
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
126
loginid INT4 REFERENCES users (loginid) NOT NULL,
127
when TIMESTAMP NOT NULL,
131
CREATE TABLE problem_prerequisites (
132
parent INT4 REFERENCES problem (problemid) NOT NULL,
133
child INT4 REFERENCES problem (problemid) NOT NULL,
134
PRIMARY KEY (parent,child)