]> Untitled Git - lemmy.git/blob - migrations/2021-02-13-210612_set_correct_aggregates_time_columns/down.sql
stop requiring superuser to run migrations (#3002)
[lemmy.git] / migrations / 2021-02-13-210612_set_correct_aggregates_time_columns / down.sql
1 create or replace function comment_aggregates_comment()
2 returns trigger language plpgsql
3 as $$
4 begin
5   IF (TG_OP = 'INSERT') THEN
6     insert into comment_aggregates (comment_id) values (NEW.id);
7   ELSIF (TG_OP = 'DELETE') THEN
8     delete from comment_aggregates where comment_id = OLD.id;
9   END IF;
10   return null;
11 end $$;
12
13 create or replace function post_aggregates_post()
14 returns trigger language plpgsql
15 as $$
16 begin
17   IF (TG_OP = 'INSERT') THEN
18     insert into post_aggregates (post_id) values (NEW.id);
19   ELSIF (TG_OP = 'DELETE') THEN
20     delete from post_aggregates where post_id = OLD.id;
21   END IF;
22   return null;
23 end $$;
24
25 create or replace function community_aggregates_community()
26 returns trigger language plpgsql
27 as $$
28 begin
29   IF (TG_OP = 'INSERT') THEN
30     insert into community_aggregates (community_id) values (NEW.id);
31   ELSIF (TG_OP = 'DELETE') THEN
32     delete from community_aggregates where community_id = OLD.id;
33   END IF;
34   return null;
35 end $$;