]> Untitled Git - lemmy.git/blob - migrations/2022-07-07-182650_comment_ltrees/down.sql
Revert "Attempt to fix CI building wrong commits (#3830)"
[lemmy.git] / migrations / 2022-07-07-182650_comment_ltrees / down.sql
1 ALTER TABLE comment
2     ADD COLUMN parent_id integer;
3
4 -- Constraints and index
5 ALTER TABLE comment
6     ADD CONSTRAINT comment_parent_id_fkey FOREIGN KEY (parent_id) REFERENCES comment (id) ON UPDATE CASCADE ON DELETE CASCADE;
7
8 CREATE INDEX idx_comment_parent ON comment (parent_id);
9
10 -- Update the parent_id column
11 -- subpath(subpath(0, -1), -1) gets the immediate parent but it fails null checks
12 UPDATE
13     comment
14 SET
15     parent_id = cast(ltree2text (nullif (subpath (nullif (subpath (path, 0, -1), '0'), -1), '0')) AS INTEGER);
16
17 ALTER TABLE comment
18     DROP COLUMN path;
19
20 ALTER TABLE comment_aggregates
21     DROP COLUMN child_count;
22
23 DROP EXTENSION ltree;
24
25 -- Add back in the read column
26 ALTER TABLE comment
27     ADD COLUMN read boolean DEFAULT FALSE NOT NULL;
28
29 UPDATE
30     comment c
31 SET
32     read = cr.read
33 FROM
34     comment_reply cr
35 WHERE
36     cr.comment_id = c.id;
37
38 CREATE VIEW comment_alias_1 AS
39 SELECT
40     *
41 FROM
42     comment;
43
44 DROP TABLE comment_reply;
45