2020-10-13 23:32:35 +00:00
|
|
|
create table comment_report (
|
2020-10-21 00:31:01 +00:00
|
|
|
id serial primary key,
|
|
|
|
creator_id int references user_ on update cascade on delete cascade not null, -- user reporting comment
|
2020-10-13 23:32:35 +00:00
|
|
|
comment_id int references comment on update cascade on delete cascade not null, -- comment being reported
|
|
|
|
comment_text text not null,
|
2020-10-21 00:31:01 +00:00
|
|
|
reason text not null,
|
|
|
|
resolved bool not null default false,
|
2020-10-25 03:24:50 +00:00
|
|
|
resolver_id int references user_ on update cascade on delete cascade, -- user resolving report
|
2020-10-21 00:31:01 +00:00
|
|
|
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 23:32:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
create table post_report (
|
2020-10-21 00:31:01 +00:00
|
|
|
id serial primary key,
|
|
|
|
creator_id int references user_ on update cascade on delete cascade not null, -- user reporting post
|
2020-10-13 23:32:35 +00:00
|
|
|
post_id int references post on update cascade on delete cascade not null, -- post being reported
|
2020-10-21 00:31:01 +00:00
|
|
|
post_name varchar(100) not null,
|
2020-10-13 23:32:35 +00:00
|
|
|
post_url text,
|
|
|
|
post_body text,
|
2020-10-21 00:31:01 +00:00
|
|
|
reason text not null,
|
|
|
|
resolved bool not null default false,
|
2020-10-25 03:24:50 +00:00
|
|
|
resolver_id int references user_ on update cascade on delete cascade, -- user resolving report
|
2020-10-21 00:31:01 +00:00
|
|
|
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 23:32:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
create or replace view comment_report_view as
|
|
|
|
select cr.*,
|
|
|
|
c.post_id,
|
2020-10-25 03:24:50 +00:00
|
|
|
c.content as current_comment_text,
|
2020-10-13 23:32:35 +00:00
|
|
|
p.community_id,
|
2020-10-21 00:31:01 +00:00
|
|
|
f.name as creator_name,
|
|
|
|
u.id as comment_creator_id,
|
|
|
|
u.name as comment_creator_name
|
2020-10-13 23:32:35 +00: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-21 00:31:01 +00:00
|
|
|
left join user_ f on f.id = cr.creator_id;
|
2020-10-13 23:32:35 +00:00
|
|
|
|
|
|
|
create or replace view post_report_view as
|
|
|
|
select pr.*,
|
2020-10-25 03:24:50 +00:00
|
|
|
p.name as current_post_name,
|
|
|
|
p.url as current_post_url,
|
|
|
|
p.body as current_post_body,
|
2020-10-13 23:32:35 +00:00
|
|
|
p.community_id,
|
2020-10-21 00:31:01 +00:00
|
|
|
f.name as creator_name,
|
|
|
|
u.id as post_creator_id,
|
|
|
|
u.name as post_creator_name
|
2020-10-13 23:32:35 +00: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-21 00:31:01 +00:00
|
|
|
left join user_ f on f.id = pr.creator_id;
|