1
DROP TABLE users CASCADE;
3
login VARCHAR UNIQUE NOT NULL,
2
4
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 ('guest', 'student',
10
unixid INT UNIQUE NOT NULL, -- unix user id
11
nick VARCHAR NOT NULL,
16
fullname VARCHAR NOT NULL,
17
7
studentid VARCHAR -- may be 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,
10
DROP TABLE groups CASCADE;
12
groupnm VARCHAR NOT NULL,
39
13
groupid SERIAL PRIMARY KEY NOT NULL,
40
offeringid INT4 REFERENCES offering (offeringid),
14
offeringid INT4 REFERENCES offerings (offeringid),
42
createdby INT4 REFERENCES login (loginid) NOT NULL,
43
epoch TIMESTAMP NOT NULL,
44
16
UNIQUE (offeringid, groupnm)
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,
19
DROP TABLE group_invitations CASCADE;
20
CREATE TABLE group_invitations (
21
loginid INT4 REFERENCES users (loginid),
22
groupid INT4 REFERENCES groups (groupid),
53
23
UNIQUE (loginid,groupid)
56
CREATE TABLE group_member (
57
loginid INT4 REFERENCES login (loginid),
58
groupid INT4 REFERENCES project_group (groupid),
59
projectid INT4 REFERENCES project (projectid),
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),
60
31
UNIQUE (loginid,projectid),
61
32
PRIMARY KEY (loginid,groupid)
35
DROP TABLE enrolment CASCADE;
64
36
CREATE TABLE enrolment (
65
loginid INT4 REFERENCES login (loginid),
66
offeringid INT4 REFERENCES offering (offeringid),
37
loginid INT4 REFERENCES users (loginid),
38
offeringid INT4 REFERENCES offerings (offeringid),
68
special_result VARCHAR,
70
special_supp_result VARCHAR,
72
42
PRIMARY KEY (loginid,offeringid)
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))
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;
84
61
CREATE TABLE project_extension (
85
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
86
projectid INT4 REFERENCES project (projectid) NOT NULL,
62
loginid INT4 REFERENCES users (loginid),
63
groupid INT4 REFERENCES groups (groupid),
64
projectid INT4 REFERENCES projects (projectid) NOT NULL,
87
65
deadline TIMESTAMP NOT NULL,
88
approver INT4 REFERENCES login (loginid) 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))
73
DROP TABLE project_mark CASCADE;
92
74
CREATE TABLE project_mark (
93
assessedid INT4 REFERENCES assessed (assessedid) NOT NULL,
94
projectid INT4 REFERENCES project (projectid) NOT NULL,
75
loginid INT4 REFERENCES users (loginid),
76
groupid INT4 REFERENCES groups (groupid),
77
projectid INT4 REFERENCES projects (projectid) NOT NULL,
96
marker INT4 REFERENCES login (loginid) NOT NULL,
79
marker INT4 REFERENCES users (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;
103
90
CREATE TABLE problem (
104
91
problemid SERIAL PRIMARY KEY NOT NULL,
108
CREATE TABLE problem_tag (
109
problemid INT4 REFERENCES problem (problemid),
95
DROP TABLE problem_tags CASCADE;
96
CREATE TABLE problem_tags (
97
problemid INT4 REFERENCES tutorial_problem (problemid),
110
98
tag VARCHAR NOT NULL,
112
standard BOOLEAN NOT NULL,
113
added_by INT4 REFERENCES login (loginid) NOT NULL,
99
added_by INT4 REFERENCES users (loginid) NOT NULL,
114
100
date TIMESTAMP NOT NULL,
115
101
PRIMARY KEY (problemid,added_by,tag)
104
DROP TABLE problem_test_case CASCADE;
118
105
CREATE TABLE problem_test_case (
119
106
problemid INT4 REFERENCES problem (problemid) NOT NULL,
120
107
testcaseid SERIAL UNIQUE NOT NULL,
123
110
visibility VARCHAR CHECK (visibility in ('public', 'protected', 'private'))
126
CREATE TABLE problem_test_case_tag (
113
DROP TABLE problem_test_case_tags CASCADE;
114
CREATE TABLE problem_test_case_tags (
127
115
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
128
116
tag VARCHAR NOT NULL,
129
117
description VARCHAR,
130
standard BOOLEAN NOT NULL,
131
added_by INT4 REFERENCES login (loginid) NOT NULL,
118
added_by INT4 REFERENCES users (loginid) NOT NULL,
132
119
date TIMESTAMP NOT NULL,
133
120
PRIMARY KEY (testcaseid,added_by,tag)
123
DROP TABLE problem_attempt CASCADE;
136
124
CREATE TABLE problem_attempt (
137
125
problemid INT4 REFERENCES problem (problemid) NOT NULL,
138
loginid INT4 REFERENCES login (loginid) NOT NULL,
126
loginid INT4 REFERENCES users (loginid) NOT NULL,
139
127
date TIMESTAMP NOT NULL,
140
128
attempt VARCHAR NOT NULL,
141
129
complete BOOLEAN NOT NULL,
142
130
PRIMARY KEY (problemid,loginid,date)
145
CREATE INDEX problem_attempt_index ON problem_attempt (problemid, loginid);
133
DROP INDEX problem_attempt_index;
134
CREATE INDEX problem_attempt_index ON problem_attempt (problemid, login);
136
DROP TABLE problem_attempt_breakdown CASCADE;
147
137
CREATE TABLE problem_attempt_breakdown (
148
138
problemid INT4 REFERENCES problem (problemid) NOT NULL,
149
139
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
150
loginid INT4 REFERENCES login (loginid) NOT NULL,
140
loginid INT4 REFERENCES users (loginid) NOT NULL,
151
141
date TIMESTAMP NOT NULL,
155
CREATE TABLE problem_prerequisite (
145
DROP TABLE problem_prerequisites CASCADE;
146
CREATE TABLE problem_prerequisites (
156
147
parent INT4 REFERENCES problem (problemid) NOT NULL,
157
148
child INT4 REFERENCES problem (problemid) NOT NULL,
158
149
PRIMARY KEY (parent,child)