1
DROP TABLE users CASCADE;
2
3
login VARCHAR UNIQUE NOT NULL,
3
4
loginid SERIAL PRIMARY KEY NOT NULL,
6
studentid VARCHAR, -- may be null
7
studentid VARCHAR -- may be null
10
DROP TABLE groups CASCADE;
9
11
CREATE TABLE groups (
10
group VARCHAR NOT NULL,
12
groupnm VARCHAR NOT NULL,
11
13
groupid SERIAL PRIMARY KEY NOT NULL,
12
14
offeringid INT4 REFERENCES offerings (offeringid),
14
UNIQUE (offeringid, group)
16
UNIQUE (offeringid, groupnm)
19
DROP TABLE group_invitations CASCADE;
17
20
CREATE TABLE group_invitations (
18
21
loginid INT4 REFERENCES users (loginid),
19
22
groupid INT4 REFERENCES groups (groupid),
20
23
UNIQUE (loginid,groupid)
26
DROP TABLE group_members CASCADE;
23
27
CREATE TABLE group_members (
24
28
loginid INT4 REFERENCES users (loginid),
25
29
groupid INT4 REFERENCES groups (groupid),
28
32
PRIMARY KEY (loginid,groupid)
35
DROP TABLE enrolment CASCADE;
31
36
CREATE TABLE enrolment (
32
37
loginid INT4 REFERENCES users (loginid),
33
38
offeringid INT4 REFERENCES offerings (offeringid),
37
42
PRIMARY KEY (loginid,offeringid)
45
DROP TABLE roles CASCADE;
40
46
CREATE TABLE roles (
41
47
loginid INT4 PRIMARY KEY REFERENCES users (loginid),
51
DROP TABLE projects CASCADE;
45
52
CREATE TABLE projects (
46
53
projectid SERIAL PRIMARY KEY NOT NULL,
60
DROP TABLE project_extension CASCADE;
53
61
CREATE TABLE project_extension (
62
loginid INT4 REFERENCES users (loginid),
63
groupid INT4 REFERENCES groups (groupid),
55
64
projectid INT4 REFERENCES projects (projectid) NOT NULL,
56
65
deadline TIMESTAMP NOT NULL,
57
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;
61
74
CREATE TABLE project_mark (
75
loginid INT4 REFERENCES users (loginid),
76
groupid INT4 REFERENCES groups (groupid),
63
77
projectid INT4 REFERENCES projects (projectid) NOT NULL,
65
79
marker INT4 REFERENCES users (loginid) NOT NULL,
70
PRIMARY KEY (loginid/groupid, projectid, componentid)
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;
73
90
CREATE TABLE problem (
74
91
problemid SERIAL PRIMARY KEY NOT NULL,
95
DROP TABLE problem_tags CASCADE;
78
96
CREATE TABLE problem_tags (
79
97
problemid INT4 REFERENCES tutorial_problem (problemid),
80
98
tag VARCHAR NOT NULL,
81
99
added_by INT4 REFERENCES users (loginid) NOT NULL,
82
when TIMESTAMP NOT NULL,
100
date TIMESTAMP NOT NULL,
83
101
PRIMARY KEY (problemid,added_by,tag)
104
DROP TABLE problem_test_case CASCADE;
86
105
CREATE TABLE problem_test_case (
87
106
problemid INT4 REFERENCES problem (problemid) NOT NULL,
88
107
testcaseid SERIAL UNIQUE NOT NULL,
91
110
visibility VARCHAR CHECK (visibility in ('public', 'protected', 'private'))
113
DROP TABLE problem_test_case_tags CASCADE;
94
114
CREATE TABLE problem_test_case_tags (
95
115
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
96
116
tag VARCHAR NOT NULL,
97
117
description VARCHAR,
98
118
added_by INT4 REFERENCES users (loginid) NOT NULL,
99
when TIMESTAMP NOT NULL,
119
date TIMESTAMP NOT NULL,
100
120
PRIMARY KEY (testcaseid,added_by,tag)
123
DROP TABLE problem_attempt CASCADE;
103
124
CREATE TABLE problem_attempt (
104
125
problemid INT4 REFERENCES problem (problemid) NOT NULL,
105
126
loginid INT4 REFERENCES users (loginid) NOT NULL,
106
when TIMESTAMP NOT NULL,
127
date TIMESTAMP NOT NULL,
107
128
attempt VARCHAR NOT NULL,
108
129
complete BOOLEAN NOT NULL,
109
PRIMARY KEY (problemid,loginid,when)
130
PRIMARY KEY (problemid,loginid,date)
112
CREATE INDEX indexname ON problem_attempt (problemid, login);
133
DROP INDEX problem_attempt_index;
134
CREATE INDEX problem_attempt_index ON problem_attempt (problemid, login);
136
DROP TABLE problem_attempt_breakdown CASCADE;
114
137
CREATE TABLE problem_attempt_breakdown (
115
138
problemid INT4 REFERENCES problem (problemid) NOT NULL,
116
139
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
117
140
loginid INT4 REFERENCES users (loginid) NOT NULL,
118
when TIMESTAMP NOT NULL,
141
date TIMESTAMP NOT NULL,
145
DROP TABLE problem_prerequisites CASCADE;
122
146
CREATE TABLE problem_prerequisites (
123
147
parent INT4 REFERENCES problem (problemid) NOT NULL,
124
148
child INT4 REFERENCES problem (problemid) NOT NULL,