]> Untitled Git - lemmy.git/blob - migrations/2022-07-07-182650_comment_ltrees/down.sql
feat: re-added captcha checks (#3249)
[lemmy.git] / migrations / 2022-07-07-182650_comment_ltrees / down.sql
1 alter table comment add column parent_id integer;
2
3 -- Constraints and index
4 alter table comment add constraint comment_parent_id_fkey foreign key (parent_id) REFERENCES comment(id) ON UPDATE CASCADE ON DELETE CASCADE;
5 create index idx_comment_parent on comment (parent_id);
6
7 -- Update the parent_id column
8 -- subpath(subpath(0, -1), -1) gets the immediate parent but it fails null checks
9 update comment set parent_id = cast(ltree2text(nullif(subpath(nullif(subpath(path, 0, -1), '0'), -1), '0')) as INTEGER);
10
11 alter table comment drop column path;
12 alter table comment_aggregates drop column child_count;
13
14 drop extension ltree;
15
16 -- Add back in the read column
17 alter table comment add column read boolean default false not null;
18
19 update comment c set read = cr.read
20 from comment_reply cr where cr.comment_id = c.id;
21
22 create view comment_alias_1 as select * from comment;    
23
24 drop table comment_reply;
25