]> Untitled Git - lemmy.git/blob - server/migrations/2020-01-21-001001_create_private_message/down.sql
routes.api: fix get_captcha endpoint (#1135)
[lemmy.git] / server / migrations / 2020-01-21-001001_create_private_message / down.sql
1 -- Drop the triggers
2 drop trigger refresh_private_message on private_message;
3 drop function refresh_private_message();
4
5 -- Drop the view and table
6 drop view private_message_view cascade;
7 drop table private_message;
8
9 -- Rebuild the old views
10 drop view user_view cascade;
11 create view user_view as 
12 select 
13 u.id,
14 u.name,
15 u.avatar,
16 u.email,
17 u.fedi_name,
18 u.admin,
19 u.banned,
20 u.show_avatars,
21 u.send_notifications_to_email,
22 u.published,
23 (select count(*) from post p where p.creator_id = u.id) as number_of_posts,
24 (select coalesce(sum(score), 0) from post p, post_like pl where u.id = p.creator_id and p.id = pl.post_id) as post_score,
25 (select count(*) from comment c where c.creator_id = u.id) as number_of_comments,
26 (select coalesce(sum(score), 0) from comment c, comment_like cl where u.id = c.creator_id and c.id = cl.comment_id) as comment_score
27 from user_ u;
28
29 create materialized view user_mview as select * from user_view;
30
31 create unique index idx_user_mview_id on user_mview (id);
32
33 -- Drop the columns
34 alter table user_ drop column matrix_user_id;