notifications table

The notifications table in the Social Media Database Schema schema has 8 columns, keyed by id, with 4 foreign keys to users, posts and comments.

actor_id null is a system notification. The partial index on unread is what keeps the badge count cheap.

Columns (8)

Columns of the notifications table
ColumnTypeConstraintsDescription
iduuidprimary key
user_iduuidnot null, references users.id
actor_iduuidreferences users.id
typenotification_typenot null
post_iduuidreferences posts.id
comment_iduuidreferences comments.id
is_readbooleannot null
created_attimestamptznot null

Indexes (1)

  • (user_id, is_read, created_at)

Relationships