]> Untitled Git - lemmy.git/blob - migrations/2019-05-02-051656_community_view_hot_rank/down.sql
routes.api: fix get_captcha endpoint (#1135)
[lemmy.git] / migrations / 2019-05-02-051656_community_view_hot_rank / down.sql
1 drop view community_view;
2 create view community_view as 
3 with all_community as
4 (
5   select *,
6   (select name from user_ u where c.creator_id = u.id) as creator_name,
7   (select name from category ct where c.category_id = ct.id) as category_name,
8   (select count(*) from community_follower cf where cf.community_id = c.id) as number_of_subscribers,
9   (select count(*) from post p where p.community_id = c.id) as number_of_posts,
10   (select count(*) from comment co, post p where c.id = p.community_id and p.id = co.post_id) as number_of_comments
11   from community c
12 )
13
14 select
15 ac.*,
16 u.id as user_id,
17 (select cf.id::boolean from community_follower cf where u.id = cf.user_id and ac.id = cf.community_id) as subscribed
18 from user_ u
19 cross join all_community ac
20
21 union all
22
23 select 
24 ac.*,
25 null as user_id,
26 null as subscribed
27 from all_community ac
28 ;