1
DO NOT APPLY THIS MIGRATION WITHOUT READING THE FOLLOWING;
2
-- This migration will delete all problem attempts and saves.
3
-- The new database schema links attempts and saves to specific worksheets.
4
-- Worksheets are linked to specific offerings.
5
-- Problems are no longer referenced by and id number, instead they are
6
-- referenced by an identifier TEXT field.
7
-- This means that in order to save your current data, you must link its
8
-- worksheet to an offering, and link the attempt to a problem identifier.
9
-- TODO: Write a script to save the problem attempts somehow.
12
-- Move the exercises from being stored as flat files, to being stored in
14
-- Drop Old, Unused tables.
15
DROP TABLE problem_attempt_breakdown;
16
DROP TABLE problem_test_case_tag;
17
DROP TABLE problem_tag;
18
DROP TABLE problem_test_case;
19
DROP TABLE problem_prerequisite;
21
-- Remove References to problemid
22
ALTER TABLE problem_attempt DROP CONSTRAINT problem_attempt_problemid_fkey;
23
ALTER TABLE problem_save DROP CONSTRAINT problem_save_problemid_fkey;
24
ALTER TABLE worksheet_problem DROP CONSTRAINT worksheet_problem_problemid_fkey;
26
-- Add fields to problem necessary to store all exercise information in non-xml
27
ALTER TABLE problem ADD COLUMN name TEXT;
28
ALTER TABLE problem ADD COLUMN description TEXT;
29
ALTER TABLE problem ADD COLUMN partial TEXT;
30
ALTER TABLE problem ADD COLUMN solution TEXT;
31
ALTER TABLE problem ADD COLUMN include TEXT;
32
ALTER TABLE problem ADD COLUMN num_rows INT4;
33
-- Drop (now) unused columns spec and problemid
34
ALTER TABLE problem DROP COLUMN spec;
35
ALTER TABLE problem DROP COLUMN problemid;
37
-- Set problems and worksheets to reference exercises by identifier
38
ALTER TABLE problem_attempt ADD COLUMN worksheetid INT4 REFERENCES worksheet (worksheetid);
39
ALTER TABLE problem_attempt DROP COLUMN problemid;
40
ALTER TABLE problem_attempt ADD COLUMN problemid TEXT REFERENCES problem (identifier);
42
ALTER TABLE problem_save ADD COLUMN worksheetid INT4 REFERENCES worksheet (worksheetid);
43
ALTER TABLE problem_save DROP COLUMN problemid;
44
ALTER TABLE problem_save ADD COLUMN problemid TEXT references problem (identifier);
46
ALTER TABLE worksheet_problem DROP COLUMN problemid;
47
ALTER TABLE worksheet_problem ADD COLUMN problemid TEXT REFERENCES problem (identifier);
49
CREATE TABLE test_suite (
50
suiteid SERIAL UNIQUE NOT NULL,
51
problemid TEXT REFERENCES problem (identifier) NOT NULL,
54
PRIMARY KEY (problemid, suiteid)
57
CREATE TABLE test_case (
58
testid SERIAL UNIQUE NOT NULL,
59
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
67
PRIMARY KEY (testid, suiteid)
70
-- Link worksheets to offerings
71
ALTER TABLE worksheet ADD COLUMN offeringid INT4 REFERENCES offering (offeringid) NOT NULL;