2023-07-20 11:13:21 -04:00
|
|
|
-- This file should undo anything in `up.sql`
|
2023-08-02 12:44:51 -04:00
|
|
|
CREATE OR REPLACE FUNCTION post_aggregates_post ()
|
|
|
|
RETURNS TRIGGER
|
2023-07-20 11:13:21 -04:00
|
|
|
LANGUAGE plpgsql
|
2023-08-02 12:44:51 -04:00
|
|
|
AS $$
|
2023-07-20 11:13:21 -04:00
|
|
|
BEGIN
|
|
|
|
IF (TG_OP = 'INSERT') THEN
|
|
|
|
INSERT INTO post_aggregates (post_id, published, newest_comment_time, newest_comment_time_necro)
|
2023-08-02 12:44:51 -04:00
|
|
|
VALUES (NEW.id, NEW.published, NEW.published, NEW.published);
|
2023-07-20 11:13:21 -04:00
|
|
|
ELSIF (TG_OP = 'DELETE') THEN
|
2023-08-02 12:44:51 -04:00
|
|
|
DELETE FROM post_aggregates
|
|
|
|
WHERE post_id = OLD.id;
|
2023-07-20 11:13:21 -04:00
|
|
|
END IF;
|
|
|
|
RETURN NULL;
|
|
|
|
END
|
|
|
|
$$;
|
|
|
|
|
2023-08-02 12:44:51 -04:00
|
|
|
ALTER TABLE post_aggregates
|
|
|
|
DROP COLUMN community_id,
|
|
|
|
DROP COLUMN creator_id;
|
2023-07-20 11:13:21 -04:00
|
|
|
|