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)

Columns of the notifications table
ColumnTypeConstraintsDescription
iduuidprimary key
user_iduuidnot null, references users.id
typenotification_typenot null
actor_iduuidreferences users.id
subreddit_iduuidreferences subreddits.id
content_typecontent_type
content_iduuid
body_previewvarchar(500)
created_attimestamptznot null
read_attimestamptz

Indexes (2)

  • (user_id, created_at)
  • (user_id, read_at)

Relationships