]> Untitled Git - lemmy.git/blob - migrations/2022-08-05-203502_add_person_post_aggregates/up.sql
Speedup CI (#3852)
[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 );
12