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)

Columns of the coin_transactions table
ColumnTypeConstraintsDescription
iduuidprimary key
user_iduuidnot null, references users.id
kindcoin_transaction_kindnot null
deltaintegernot null
balance_afterintegernot null
reference_typevarchar(40)
reference_iduuid
created_attimestamptznot null

Indexes (2)

  • (user_id, created_at)
  • (kind, created_at)

Relationships

  • coin_transactions.user_id references users.id