192
--TODO: Add in a field for the user-friendly identifier
193
193
CREATE TABLE problem (
194
problemid SERIAL PRIMARY KEY NOT NULL,
195
identifier VARCHAR UNIQUE NOT NULL,
194
identifier VARCHAR PRIMARY KEY NOT NULL,
203
--TODO: Link worksheets to offerings
199
204
CREATE TABLE worksheet (
200
205
worksheetid SERIAL PRIMARY KEY NOT NULL,
201
206
subject VARCHAR NOT NULL,
207
offeringid INT4 REFERENCES offering (offeringid) NOT NULL,
202
208
identifier VARCHAR NOT NULL,
203
209
assessable BOOLEAN,
208
214
CREATE TABLE worksheet_problem (
209
215
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
210
problemid INT4 REFERENCES problem (problemid) NOT NULL,
216
problemid TEXT REFERENCES problem (identifier) NOT NULL,
211
217
optional BOOLEAN,
212
218
PRIMARY KEY (worksheetid, problemid)
215
CREATE TABLE problem_tag (
216
problemid INT4 REFERENCES problem (problemid),
217
tag VARCHAR NOT NULL,
219
standard BOOLEAN NOT NULL,
220
added_by INT4 REFERENCES login (loginid) NOT NULL,
221
date TIMESTAMP NOT NULL,
222
PRIMARY KEY (problemid,added_by,tag)
225
CREATE TABLE problem_test_case (
226
problemid INT4 REFERENCES problem (problemid) NOT NULL,
227
testcaseid SERIAL UNIQUE NOT NULL,
230
visibility VARCHAR CHECK (visibility in ('public', 'protected', 'private'))
233
CREATE TABLE problem_test_case_tag (
234
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
235
tag VARCHAR NOT NULL,
237
standard BOOLEAN NOT NULL,
238
added_by INT4 REFERENCES login (loginid) NOT NULL,
239
date TIMESTAMP NOT NULL,
240
PRIMARY KEY (testcaseid,added_by,tag)
243
221
CREATE TABLE problem_attempt (
244
problemid INT4 REFERENCES problem (problemid) NOT NULL,
222
problemid VARCHAR REFERENCES problem (identifier) NOT NULL,
245
223
loginid INT4 REFERENCES login (loginid) NOT NULL,
224
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
246
225
date TIMESTAMP NOT NULL,
247
226
attempt VARCHAR NOT NULL,
248
227
complete BOOLEAN NOT NULL,
253
232
CREATE TABLE problem_save (
254
233
problemid INT4 REFERENCES problem (problemid) NOT NULL,
255
234
loginid INT4 REFERENCES login (loginid) NOT NULL,
235
worksheetid INT4 REFERENCES worksheet (worksheetid) NOT NULL,
256
236
date TIMESTAMP NOT NULL,
257
237
text VARCHAR NOT NULL,
258
238
PRIMARY KEY (problemid,loginid)
261
241
CREATE INDEX problem_attempt_index ON problem_attempt (problemid, loginid);
263
CREATE TABLE problem_attempt_breakdown (
264
problemid INT4 REFERENCES problem (problemid) NOT NULL,
265
testcaseid INT4 REFERENCES problem_test_case (testcaseid) NOT NULL,
266
loginid INT4 REFERENCES login (loginid) NOT NULL,
267
date TIMESTAMP NOT NULL,
271
CREATE TABLE problem_prerequisite (
272
parent INT4 REFERENCES problem (problemid) NOT NULL,
273
child INT4 REFERENCES problem (problemid) NOT NULL,
274
PRIMARY KEY (parent,child)
243
-- TABLES FOR EXERCISES IN DATABASE --
244
CREATE TABLE test_suite (
245
suiteid SERIAL NOT NULL,
246
problemid TEXT REFERENCES problem (identifier) NOT NULL,
249
PRIMARY KEY (problemid, suiteid)
252
CREATE TABLE test_case (
253
testid SERIAL NOT NULL,
254
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
262
PRIMARY KEY (testid, suiteid)