1
DROP TABLE users CASCADE;
2
loginid SERIAL PRIMARY KEY NOT NULL,
3
3
login VARCHAR UNIQUE NOT NULL,
4
loginid SERIAL PRIMARY KEY NOT NULL,
5
state VARCHAR NOT NULL CHECK (state in ('no_agreement', 'pending',
6
'enabled', 'disabled')),
7
rolenm VARCHAR NOT NULL CHECK (rolenm in ('guest', 'student',
10
unixid INT UNIQUE NOT NULL, -- unix user id
11
nick VARCHAR NOT NULL,
16
fullname VARCHAR NOT NULL,
7
17
studentid VARCHAR -- may be null
10
DROP TABLE groups CASCADE;
12
groupnm VARCHAR NOT NULL,
20
CREATE TABLE offering (
21
offeringid SERIAL PRIMARY KEY NOT NULL,
22
subj_name VARCHAR NOT NULL,
23
subj_code VARCHAR NOT NULL,
24
year CHAR(4) NOT NULL,
25
semester CHAR(1) NOT NULL,
29
CREATE TABLE project (
30
projectid SERIAL PRIMARY KEY NOT NULL,
33
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
37
CREATE TABLE project_group (
38
groupnm VARCHAR NOT NULL,
13
39
groupid SERIAL PRIMARY KEY NOT NULL,
14
offeringid INT4 REFERENCES offerings (offeringid),
40
offeringid INT4 REFERENCES offering (offeringid),
42
createdby INT4 REFERENCES login (loginid) NOT NULL,
43
epoch TIMESTAMP NOT NULL,
16
44
UNIQUE (offeringid, groupnm)
19
DROP TABLE group_invitations CASCADE;
20
CREATE TABLE group_invitations (
21
loginid INT4 REFERENCES users (loginid),
22
groupid INT4 REFERENCES groups (groupid),
47
CREATE TABLE group_invitation (
48
loginid INT4 REFERENCES login (loginid) NOT NULL,
49
groupid INT4 REFERENCES project_group (groupid) NOT NULL,
50
inviter INT4 REFERENCES login (loginid) NOT NULL,
51
invited TIMESTAMP NOT NULL,
23
53
UNIQUE (loginid,groupid)
26
DROP TABLE group_members CASCADE;
27
CREATE TABLE group_members (
28
loginid INT4 REFERENCES users (loginid),
29
groupid INT4 REFERENCES groups (groupid),
30
projectid INT4 REFERENCES projects (projectid),
56
CREATE TABLE group_member (
57
loginid INT4 REFERENCES login (loginid),
58
groupid INT4 REFERENCES project_group (groupid),
59
projectid INT4 REFERENCES project (projectid),
31
60
UNIQUE (loginid,projectid),
32
61
PRIMARY KEY (loginid,groupid)
35
DROP TABLE enrolment CASCADE;
36
64
CREATE TABLE enrolment (
37
loginid INT4 REFERENCES users (loginid),
38
offeringid INT4 REFERENCES offerings (offeringid),
65
loginid INT4 REFERENCES login (loginid),
66
offeringid INT4 REFERENCES offering (offeringid),
68
special_result VARCHAR,
70
special_supp_result VARCHAR,
42
72
PRIMARY KEY (loginid,offeringid)
45
DROP TABLE roles CASCADE;
47
loginid INT4 PRIMARY KEY REFERENCES users (loginid),
51
DROP TABLE projects CASCADE;
52
CREATE TABLE projects (
53
projectid SERIAL PRIMARY KEY NOT NULL,
56
offeringid INT4 REFERENCES offerings (offeringid) NOT NULL,
60
DROP TABLE project_extension CASCADE;
75
CREATE TABLE assessed (
76
assessedid SERIAL PRIMARY KEY NOT NULL,
77
loginid INT4 REFERENCES login (loginid),
78
groupid INT4 REFERENCES project_group (groupid),
79
-- exactly one of loginid and groupid must be non-null
80
CHECK ((loginid IS NOT NULL AND groupid IS NULL)
81
OR (loginid IS NULL AND groupid IS NOT NULL))
61
84
CREATE TABLE project_extension (
62
loginid INT4 REFERENCES users (loginid),
63
groupid INT4 REFERENCES groups (groupid),
64
projectid INT4 REFERENCES projects (projectid) NOT NULL,
85
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
86
projectid INT4 REFERENCES project (projectid) NOT NULL,
65
87
deadline TIMESTAMP NOT NULL,
66
approver INT4 REFERENCES users (loginid) NOT NULL,
68
-- exactly one of loginid and groupid must be non-null
69
CHECK ((loginid IS NOT NULL AND groupid IS NULL)
70
OR (loginid IS NULL AND groupid IS NOT NULL))
88
approver INT4 REFERENCES login (loginid) NOT NULL,
73
DROP TABLE project_mark CASCADE;
74
92
CREATE TABLE project_mark (
75
loginid INT4 REFERENCES users (loginid),
76
groupid INT4 REFERENCES groups (groupid),
77
projectid INT4 REFERENCES projects (projectid) NOT NULL,
93
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
94
projectid INT4 REFERENCES project (projectid) NOT NULL,
79
marker INT4 REFERENCES users (loginid) NOT NULL,
96
marker INT4 REFERENCES login (loginid) NOT NULL,
84
-- exactly one of loginid and groupid must be non-null
85
CHECK ((loginid IS NOT NULL AND groupid IS NULL)
86
OR (loginid IS NULL AND groupid IS NOT NULL))
89
DROP TABLE problem CASCADE;
90
103
CREATE TABLE problem (
91
104
problemid SERIAL PRIMARY KEY NOT NULL,
95
DROP TABLE problem_tags CASCADE;
96
CREATE TABLE problem_tags (
97
problemid INT4 REFERENCES tutorial_problem (problemid),
108
CREATE TABLE problem_tag (
109
problemid INT4 REFERENCES problem (problemid),
98
110
tag VARCHAR NOT NULL,
99
added_by INT4 REFERENCES users (loginid) NOT NULL,
112
standard BOOLEAN NOT NULL,
113
added_by INT4 REFERENCES login (loginid) NOT NULL,
100
114
date TIMESTAMP NOT NULL,
101
115
PRIMARY KEY (problemid,added_by,tag)
104
DROP TABLE problem_test_case CASCADE;
105
118
CREATE TABLE problem_test_case (
106
119
problemid INT4 REFERENCES problem (problemid) NOT NULL,
107
120
testcaseid SERIAL UNIQUE NOT NULL,
110
123
visibility VARCHAR CHECK (visibility in ('public', 'protected', 'private'))
113
DROP TABLE problem_test_case_tags CASCADE;
114
CREATE TABLE problem_test_case_tags (
126
CREATE TABLE problem_test_case_tag (
115
127
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
116
128
tag VARCHAR NOT NULL,
117
129
description VARCHAR,
118
added_by INT4 REFERENCES users (loginid) NOT NULL,
130
standard BOOLEAN NOT NULL,
131
added_by INT4 REFERENCES login (loginid) NOT NULL,
119
132
date TIMESTAMP NOT NULL,
120
133
PRIMARY KEY (testcaseid,added_by,tag)
123
DROP TABLE problem_attempt CASCADE;
124
136
CREATE TABLE problem_attempt (
125
137
problemid INT4 REFERENCES problem (problemid) NOT NULL,
126
loginid INT4 REFERENCES users (loginid) NOT NULL,
138
loginid INT4 REFERENCES login (loginid) NOT NULL,
127
139
date TIMESTAMP NOT NULL,
128
140
attempt VARCHAR NOT NULL,
129
141
complete BOOLEAN NOT NULL,
130
142
PRIMARY KEY (problemid,loginid,date)
133
DROP INDEX problem_attempt_index;
134
CREATE INDEX problem_attempt_index ON problem_attempt (problemid, login);
145
CREATE INDEX problem_attempt_index ON problem_attempt (problemid, loginid);
136
DROP TABLE problem_attempt_breakdown CASCADE;
137
147
CREATE TABLE problem_attempt_breakdown (
138
148
problemid INT4 REFERENCES problem (problemid) NOT NULL,
139
149
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
140
loginid INT4 REFERENCES users (loginid) NOT NULL,
150
loginid INT4 REFERENCES login (loginid) NOT NULL,
141
151
date TIMESTAMP NOT NULL,
145
DROP TABLE problem_prerequisites CASCADE;
146
CREATE TABLE problem_prerequisites (
155
CREATE TABLE problem_prerequisite (
147
156
parent INT4 REFERENCES problem (problemid) NOT NULL,
148
157
child INT4 REFERENCES problem (problemid) NOT NULL,
149
158
PRIMARY KEY (parent,child)