votes table

The votes table in the Forum Database Schema schema has 4 columns, with 2 foreign keys to users and posts.

value is +1 or -1, constrained by a check. The composite key makes a vote idempotent and lets a user flip it with an UPDATE rather than accumulating rows.

Columns (4)

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

Indexes (1)

  • (post_id)

Relationships