notifications table
The notifications table in the Reddit Clone Database Schema schema has 10 columns, keyed by id, with 3 foreign keys to users and subreddits.
The orange envelope. Replies, mentions, award receipts, mod invites and ban notices all land here so the inbox is one query. read_at null IS the unread count, which is why it is indexed rather than being a boolean.
Columns (10)
| Column | Type | Constraints | Description |
|---|---|---|---|
| id | uuid | primary key | |
| user_id | uuid | not null, references users.id | |
| type | notification_type | not null | |
| actor_id | uuid | references users.id | |
| subreddit_id | uuid | references subreddits.id | |
| content_type | content_type | ||
| content_id | uuid | ||
| body_preview | varchar(500) | ||
| created_at | timestamptz | not null | |
| read_at | timestamptz |
Indexes (2)
(user_id, created_at)(user_id, read_at)
Relationships
notifications.user_idreferencesusers.idnotifications.actor_idreferencesusers.idnotifications.subreddit_idreferencessubreddits.id