1 alter table comment add column parent_id integer;
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);
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);
11 alter table comment drop column path;
12 alter table comment_aggregates drop column child_count;
16 -- Add back in the read column
17 alter table comment add column read boolean default false not null;
19 update comment c set read = cr.read
20 from comment_reply cr where cr.comment_id = c.id;
22 create view comment_alias_1 as select * from comment;
24 drop table comment_reply;