]> Untitled Git - lemmy.git/blob - migrations/2021-02-13-210612_set_correct_aggregates_time_columns/up.sql
Remove federation settings, rely on sensible defaults instead (#2574)
[lemmy.git] / migrations / 2021-02-13-210612_set_correct_aggregates_time_columns / up.sql
1 -- The published and updated columns on the aggregates tables are using now(), 
2 -- when they should use the correct published or updated columns
3 -- This is mainly a problem with federated posts being fetched
4
5 create or replace function comment_aggregates_comment()
6 returns trigger language plpgsql
7 as $$
8 begin
9   IF (TG_OP = 'INSERT') THEN
10     insert into comment_aggregates (comment_id, published) values (NEW.id, NEW.published);
11   ELSIF (TG_OP = 'DELETE') THEN
12     delete from comment_aggregates where comment_id = OLD.id;
13   END IF;
14   return null;
15 end $$;
16
17 create or replace function post_aggregates_post()
18 returns trigger language plpgsql
19 as $$
20 begin
21   IF (TG_OP = 'INSERT') THEN
22     insert into post_aggregates (post_id, published, newest_comment_time, newest_comment_time_necro) values (NEW.id, NEW.published, NEW.published, NEW.published);
23   ELSIF (TG_OP = 'DELETE') THEN
24     delete from post_aggregates where post_id = OLD.id;
25   END IF;
26   return null;
27 end $$;
28
29 create or replace function community_aggregates_community()
30 returns trigger language plpgsql
31 as $$
32 begin
33   IF (TG_OP = 'INSERT') THEN
34     insert into community_aggregates (community_id, published) values (NEW.id, NEW.published);
35   ELSIF (TG_OP = 'DELETE') THEN
36     delete from community_aggregates where community_id = OLD.id;
37   END IF;
38   return null;
39 end $$;