karma_events table

The karma_events table in the Reddit Clone Database Schema schema has 8 columns, keyed by id, with 2 foreign keys to users and subreddits.

The append-only ledger behind every karma column on users. Keeping the subreddit on each row is what makes per-community karma and karma-gated posting possible without a second aggregation. Nothing here is ever updated.

Columns (8)

Columns of the karma_events table
ColumnTypeConstraintsDescription
iduuidprimary key
user_iduuidnot null, references users.id
sourcekarma_sourcenot null
content_typecontent_type
content_iduuid
subreddit_iduuidreferences subreddits.id
deltaintegernot null
created_attimestamptznot null

Indexes (3)

  • (user_id, created_at)
  • (user_id, source)
  • (subreddit_id, user_id)

Relationships