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)
| Column | Type | Constraints | Description |
|---|---|---|---|
| id | uuid | primary key | |
| user_id | uuid | not null, references users.id | |
| source | karma_source | not null | |
| content_type | content_type | ||
| content_id | uuid | ||
| subreddit_id | uuid | references subreddits.id | |
| delta | integer | not null | |
| created_at | timestamptz | not null |
Indexes (3)
(user_id, created_at)(user_id, source)(subreddit_id, user_id)
Relationships
karma_events.user_idreferencesusers.idkarma_events.subreddit_idreferencessubreddits.id