]> Untitled Git - lemmy.git/blob - migrations/2022-11-20-032430_sticky_local/down.sql
Add support for Featured Posts (#2585)
[lemmy.git] / migrations / 2022-11-20-032430_sticky_local / down.sql
1
2 DROP TRIGGER IF EXISTS post_aggregates_featured_local ON post;
3 DROP TRIGGER IF EXISTS post_aggregates_featured_community ON post;
4 drop function post_aggregates_featured_community;
5 drop function post_aggregates_featured_local;
6
7
8 alter table post ADD stickied boolean NOT NULL DEFAULT false;
9 Update post
10 set stickied = featured_community;
11 alter table post DROP COLUMN featured_community;
12 alter table post DROP COLUMN featured_local;
13
14 alter table post_aggregates ADD stickied boolean NOT NULL DEFAULT false;
15 Update post_aggregates
16 set stickied = featured_community;
17 alter table post_aggregates DROP COLUMN featured_community;
18 alter table post_aggregates DROP COLUMN featured_local;
19
20 alter table mod_feature_post
21 rename column featured TO stickied;
22
23 alter table mod_feature_post
24 DROP COLUMN is_featured_community;
25
26 alter table mod_feature_post
27 alter column stickied DROP NOT NULL;
28
29 alter table mod_feature_post
30 Rename To mod_sticky_post;
31
32 create function post_aggregates_stickied()
33 returns trigger language plpgsql
34 as $$
35 begin
36   update post_aggregates pa
37   set stickied = NEW.stickied
38   where pa.post_id = NEW.id;
39
40   return null;
41 end $$;
42
43 create trigger post_aggregates_stickied
44 after update on post
45 for each row
46 when (OLD.stickied is distinct from NEW.stickied)
47 execute procedure post_aggregates_stickied();