coin_transactions table
The coin_transactions table in the Reddit Clone Database Schema schema has 8 columns, keyed by id, with 1 foreign key to users.
The append-only coin ledger with a signed delta, the same shape as karma_events and stock movements. balance_after is stored so a statement can be rendered without re-summing the whole history, and a mismatch between it and the running sum is the alarm that something wrote out of band.
Columns (8)
| Column | Type | Constraints | Description |
|---|---|---|---|
| id | uuid | primary key | |
| user_id | uuid | not null, references users.id | |
| kind | coin_transaction_kind | not null | |
| delta | integer | not null | |
| balance_after | integer | not null | |
| reference_type | varchar(40) | ||
| reference_id | uuid | ||
| created_at | timestamptz | not null |
Indexes (2)
(user_id, created_at)(kind, created_at)
Relationships
coin_transactions.user_idreferencesusers.id