]> Untitled Git - lemmy.git/blob - migrations/2023-07-18-082614_post_aggregates_community_id/down.sql
UI Settings - Blur NSFW & Auto Expand (#3377)
[lemmy.git] / migrations / 2023-07-18-082614_post_aggregates_community_id / down.sql
1 -- This file should undo anything in `up.sql`
2
3 CREATE OR REPLACE FUNCTION post_aggregates_post()
4     RETURNS trigger
5     LANGUAGE plpgsql
6 AS
7 $$
8 BEGIN
9     IF (TG_OP = 'INSERT') THEN
10         INSERT INTO post_aggregates (post_id, published, newest_comment_time, newest_comment_time_necro)
11         VALUES (NEW.id, NEW.published, NEW.published, NEW.published);
12     ELSIF (TG_OP = 'DELETE') THEN
13         DELETE FROM post_aggregates WHERE post_id = OLD.id;
14     END IF;
15     RETURN NULL;
16 END
17 $$;
18
19 ALTER TABLE post_aggregates DROP COLUMN community_id, DROP COLUMN creator_id;
20