lemmy/migrations/2022-08-05-203502_add_person_post_aggregates/up.sql
Dessalines 0aeb78b8f3
Showing # of unread comments for posts. Fixes #2134 (#2393)
* Showing # of unread comments for posts. Fixes #2134

* Fix lint.

* Forgot to remove comment list update.

* Fix clippy
2022-09-27 16:45:46 +00:00

12 lines
551 B
SQL

-- This table stores the # of read comments for a person, on a post
-- It can then be joined to post_aggregates to get an unread count:
-- unread = post_aggregates.comments - person_post_aggregates.read_comments
create table person_post_aggregates(
id serial primary key,
person_id int references person on update cascade on delete cascade not null,
post_id int references post on update cascade on delete cascade not null,
read_comments bigint not null default 0,
published timestamp not null default now(),
unique(person_id, post_id)
);