Skip to main content

Player Balances

Stores the current balance state for each player, segmented by currency type and balance type. Uses a composite primary key — each player has multiple rows representing different balance pools.

Relationships

Columns

ColumnTypeNullableDefaultDescription
player_iduuidNOFK to players. Part of composite PK.
currency_typevarchar(50)NOCurrency identifier: gc (Gold Coins), sc (Sweepstakes Coins), real_money, etc. Part of composite PK.
balance_typebalance_type_enumNOEnum: withdrawable or non-withdrawable. Part of composite PK.
balancenumeric(18)NOCurrent balance amount
metadatajsonbYESJSON metadata containing currency conversion info: display_currency, display_amount, original_conversion_rate, etc.
updated_attimestamptzYESnow()Last update timestamp (managed by trigger)

Primary Key

The table uses a composite primary key: (player_id, currency_type, balance_type)

This means a single player may have multiple rows, for example:

player_idcurrency_typebalance_typebalance
abc-123gcwithdrawable50000
abc-123gcnon-withdrawable10000
abc-123scwithdrawable25.50
abc-123scnon-withdrawable5.00

Balance Type Enum

ValueDescription
withdrawableCash/real balance. Can be withdrawn or redeemed.
non-withdrawableBonus balance. Must meet wagering requirements before becoming withdrawable.

Key Indexes

IndexColumnsNotes
player_balances_pkeyplayer_id, currency_type, balance_typeComposite primary key
idx_player_balances_player_idplayer_idAll balances for a player
idx_player_balances_compositeplayer_id, currency_type, balance_typeOptimized lookup
idx_player_balances_lookupplayer_id, balance_type, currency_typeAlternative ordering for different query patterns
idx_player_balances_player_lookupplayer_idCovering index including balance, balance_type, currency_type
idx_player_balances_balance_typebalance_typeFilter by balance type
idx_player_balances_currency_typecurrency_typeFilter by currency
idx_player_balances_metadatametadataGIN index for JSONB queries
idx_player_balances_trigger_updateplayer_id, currency_type, balance_typeOptimizes trigger lookups from transactions

Triggers

TriggerFunctionDescription
set_player_balance_updated_at_triggerset_player_balance_updated_atAuto-updates updated_at on balance change
trigger_cap_redeemable_sccap_redeemable_sc_on_balance_changeEnsures redeemable_sc on players never exceeds the actual SC withdrawable balance

Business Rules

  • Balances are never updated directly — they are maintained exclusively by triggers on the transactions table
  • The withdrawable vs non-withdrawable distinction is critical for regulatory compliance:
    • Withdrawable (cash): Can be redeemed/withdrawn at any time
    • Non-withdrawable (bonus): Requires wagering playthrough before conversion to withdrawable
  • The metadata field stores currency display information for multi-currency support
  • The cap_redeemable_sc trigger ensures the redeemable_sc field on the players table stays consistent with the actual SC withdrawable balance
  • For sweepstakes brands, the typical balance rows are: gc/withdrawable, sc/withdrawable, sc/non-withdrawable