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;
20
TRUNCATE worksheet_problem, worksheet;
22
-- Remove References to problemid
23
ALTER TABLE problem_attempt DROP CONSTRAINT problem_attempt_problemid_fkey;
24
ALTER TABLE problem_save DROP CONSTRAINT problem_save_problemid_fkey;
25
ALTER TABLE worksheet_problem DROP CONSTRAINT worksheet_problem_problemid_fkey;
27
-- Add fields to problem necessary to store all exercise information in non-xml
28
ALTER TABLE problem ADD COLUMN name TEXT;
29
ALTER TABLE problem ADD COLUMN description TEXT;
30
ALTER TABLE problem ADD COLUMN partial TEXT;
31
ALTER TABLE problem ADD COLUMN solution TEXT;
32
ALTER TABLE problem ADD COLUMN include TEXT;
33
ALTER TABLE problem ADD COLUMN num_rows INT4;
34
-- Drop (now) unused columns spec and problemid
35
ALTER TABLE problem DROP COLUMN spec;
36
ALTER TABLE problem DROP COLUMN problemid;
38
-- Set problems and worksheets to reference exercises by identifier
39
ALTER TABLE problem_attempt ADD COLUMN worksheetid INT4 REFERENCES worksheet (worksheetid);
40
ALTER TABLE problem_attempt DROP COLUMN problemid;
41
ALTER TABLE problem_attempt ADD COLUMN problemid TEXT REFERENCES problem (identifier);
43
ALTER TABLE problem_save ADD COLUMN worksheetid INT4 REFERENCES worksheet (worksheetid);
44
ALTER TABLE problem_save DROP COLUMN problemid;
45
ALTER TABLE problem_save ADD COLUMN problemid TEXT references problem (identifier);
47
ALTER TABLE worksheet_problem DROP COLUMN problemid;
48
ALTER TABLE worksheet_problem ADD COLUMN problemid TEXT REFERENCES problem (identifier);
50
CREATE TABLE test_suite (
51
suiteid SERIAL UNIQUE NOT NULL,
52
problemid TEXT REFERENCES problem (identifier) NOT NULL,
55
PRIMARY KEY (problemid, suiteid)
58
CREATE TABLE test_case (
59
testid SERIAL UNIQUE NOT NULL,
60
suiteid INT4 REFERENCES test_suite (suiteid) NOT NULL,
68
PRIMARY KEY (testid, suiteid)
71
-- Link worksheets to offerings
72
ALTER TABLE worksheet ADD COLUMN offeringid INT4 REFERENCES offering (offeringid) NOT NULL;