post_votes table

The post_votes table in the Reddit Clone Database Schema schema has 5 columns, with 2 foreign keys to users and posts.

value is +1 or -1 under a check constraint. The composite key makes a vote idempotent, so changing your mind is an UPDATE and un-voting is a DELETE rather than an accumulating pile of rows. Every count on posts is rebuildable from here.

Columns (5)

Columns of the post_votes table
ColumnTypeConstraintsDescription
user_iduuidnot null, references users.id
post_iduuidnot null, references posts.id
valuesmallintnot null
created_attimestamptznot null
updated_attimestamptznot null

Indexes (2)

  • (post_id)
  • (user_id, created_at)

Relationships