]> Untitled Git - lemmy.git/blob - migrations/2022-08-05-203502_add_person_post_aggregates/up.sql
9a0a5fa5f39a4885569e9f8b29af5eff77cd0b28
[lemmy.git] / migrations / 2022-08-05-203502_add_person_post_aggregates / up.sql
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(
5   id serial primary key,
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)
11 );