]> Untitled Git - lemmy.git/blob - migrations/2020-01-29-011901_create_reply_materialized_view/down.sql
routes.api: fix get_captcha endpoint (#1135)
[lemmy.git] / migrations / 2020-01-29-011901_create_reply_materialized_view / down.sql
1 -- Drop the materialized / built views
2 drop view reply_view;
3 create view reply_view as 
4 with closereply as (
5     select 
6     c2.id, 
7     c2.creator_id as sender_id, 
8     c.creator_id as recipient_id
9     from comment c
10     inner join comment c2 on c.id = c2.parent_id
11     where c2.creator_id != c.creator_id
12     -- Do union where post is null
13     union
14     select
15     c.id,
16     c.creator_id as sender_id,
17     p.creator_id as recipient_id
18     from comment c, post p
19     where c.post_id = p.id and c.parent_id is null and c.creator_id != p.creator_id
20 )
21 select cv.*,
22 closereply.recipient_id
23 from comment_view cv, closereply
24 where closereply.id = cv.id
25 ;