1 -- This table stores the # of read comments for a person, on a post
2 -- It can then be joined to post_aggregates to get an unread count:
3 -- unread = post_aggregates.comments - person_post_aggregates.read_comments
4 CREATE TABLE person_post_aggregates (
6 person_id int REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
7 post_id int REFERENCES post ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
8 read_comments bigint NOT NULL DEFAULT 0,
9 published timestamp NOT NULL DEFAULT now(),
10 UNIQUE (person_id, post_id)