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