2020-10-13 17:32:35 -06:00
|
|
|
create table comment_report (
|
2020-10-20 18:31:01 -06:00
|
|
|
id serial primary key,
|
|
|
|
creator_id int references user_ on update cascade on delete cascade not null, -- user reporting comment
|
2020-10-13 17:32:35 -06:00
|
|
|
comment_id int references comment on update cascade on delete cascade not null, -- comment being reported
|
|
|
|
comment_text text not null,
|
2020-10-20 18:31:01 -06:00
|
|
|
reason text not null,
|
|
|
|
resolved bool not null default false,
|
|
|
|
resolver_id int references user_ on update cascade on delete cascade not null, -- user resolving report
|
|
|
|
published timestamp not null default now(),
|
|
|
|
updated timestamp null,
|
|
|
|
unique(comment_id, creator_id) -- users should only be able to report a comment once
|
2020-10-13 17:32:35 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
create table post_report (
|
2020-10-20 18:31:01 -06:00
|
|
|
id serial primary key,
|
|
|
|
creator_id int references user_ on update cascade on delete cascade not null, -- user reporting post
|
2020-10-13 17:32:35 -06:00
|
|
|
post_id int references post on update cascade on delete cascade not null, -- post being reported
|
2020-10-20 18:31:01 -06:00
|
|
|
post_name varchar(100) not null,
|
2020-10-13 17:32:35 -06:00
|
|
|
post_url text,
|
|
|
|
post_body text,
|
2020-10-20 18:31:01 -06:00
|
|
|
reason text not null,
|
|
|
|
resolved bool not null default false,
|
|
|
|
resolver_id int references user_ on update cascade on delete cascade not null, -- user resolving report
|
|
|
|
published timestamp not null default now(),
|
|
|
|
updated timestamp null,
|
|
|
|
unique(post_id, creator_id) -- users should only be able to report a post once
|
2020-10-13 17:32:35 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
create or replace view comment_report_view as
|
|
|
|
select cr.*,
|
|
|
|
c.post_id,
|
|
|
|
p.community_id,
|
2020-10-20 18:31:01 -06:00
|
|
|
f.name as creator_name,
|
|
|
|
u.id as comment_creator_id,
|
|
|
|
u.name as comment_creator_name
|
2020-10-13 17:32:35 -06:00
|
|
|
from comment_report cr
|
|
|
|
left join comment c on c.id = cr.comment_id
|
|
|
|
left join post p on p.id = c.post_id
|
|
|
|
left join user_ u on u.id = c.creator_id
|
2020-10-20 18:31:01 -06:00
|
|
|
left join user_ f on f.id = cr.creator_id;
|
2020-10-13 17:32:35 -06:00
|
|
|
|
|
|
|
create or replace view post_report_view as
|
|
|
|
select pr.*,
|
|
|
|
p.community_id,
|
2020-10-20 18:31:01 -06:00
|
|
|
f.name as creator_name,
|
|
|
|
u.id as post_creator_id,
|
|
|
|
u.name as post_creator_name
|
2020-10-13 17:32:35 -06:00
|
|
|
from post_report pr
|
|
|
|
left join post p on p.id = pr.post_id
|
|
|
|
left join user_ u on u.id = p.creator_id
|
2020-10-20 18:31:01 -06:00
|
|
|
left join user_ f on f.id = pr.creator_id;
|