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)