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