coin_balances table
The coin_balances table in the Reddit Clone Database Schema schema has 6 columns, keyed by user_id. 1 column in users references it.
A cached running total. The truth is coin_transactions, and this row can always be rebuilt by summing it. users.coin_balance mirrors this again for the header badge, because that number is read on literally every page.
Columns (6)
| Column | Type | Constraints | Description |
|---|---|---|---|
| user_id | uuid | primary key | |
| balance | integer | not null | |
| lifetime_purchased | integer | not null | |
| lifetime_earned | integer | not null | |
| lifetime_spent | integer | not null | |
| updated_at | timestamptz | not null |
Relationships
users.idreferencescoin_balances