Skip to main content

Transactions

The core financial ledger table recording every monetary movement in the system. Every deposit, withdrawal, bet, win, bonus credit, and reward is recorded as a transaction with full balance snapshots.

Relationships

  • Belongs to players via player_id
  • Belongs to brands via brand_id
  • Belongs to companies via company_id
  • Optionally references bonuses via bonus_id
  • Optionally references promotions via promotion_id
  • Optionally references player_bonuses via player_bonus_id
  • Optionally references game_sessions via game_session_id
  • Referenced by players via first_purchase_transaction_id
  • Referenced by vip_daily_cashback_log via transaction_id

Columns

ColumnTypeNullableDefaultDescription
iduuidNOgen_random_uuid()Primary key
player_iduuidNOFK to players. The player this transaction belongs to.
brand_iduuidNOFK to brands. The brand context.
company_iduuidNOFK to companies. Parent company.
transaction_typevarchar(50)NODirection of the transaction: credit (money in) or debit (money out)
transaction_categoryvarchar(50)NOBusiness category. See values below.
currency_typevarchar(50)NOCurrency of the transaction: gc (Gold Coins), sc (Sweepstakes Coins), real_money, etc.
cash_currencyvarchar(50)YESFiat currency code when currency_type = 'real_money' (e.g., EUR, USD)
balance_typebalance_type_enumNOEnum: withdrawable or non-withdrawable. Determines which balance pool is affected.
amountnumeric(18)NOTransaction amount (always positive; direction determined by transaction_type)
statusvarchar(20)YES'completed'Values: completed, pending, cancelled, failed
payment_methodvarchar(50)YESPayment method used (for deposits/withdrawals)
payment_method_detailsjsonbYESDetailed payment method info (card last 4, provider response, etc.)
external_transaction_idtextYESExternal payment provider transaction reference
game_session_iduuidYESFK to game_sessions. Links bet/win transactions to a game round.
bonus_iduuidYESFK to bonuses. The bonus template if this transaction is bonus-related.
promotion_iduuidYESFK to promotions. The promotion that triggered this transaction.
player_bonus_iduuidYESFK to player_bonuses. The specific player bonus instance.
eur_amountnumeric(18)YESAmount converted to EUR (for unified reporting)
eur_conversion_ratenumeric(18)YESEUR conversion rate used at time of transaction
total_balance_beforenumeric(18)YESSnapshot: Total balance (withdrawable + non-withdrawable) BEFORE this transaction
total_balance_afternumeric(18)YESSnapshot: Total balance AFTER this transaction
cash_balance_beforenumeric(18)YESSnapshot: Withdrawable balance BEFORE. Example: Player has $100 withdrawable, makes $20 bet -> cash_balance_before = 100
cash_balance_afternumeric(18)YESSnapshot: Withdrawable balance AFTER. Example: Player has $100, makes $20 bet -> cash_balance_after = 80
bonus_balance_beforenumeric(18)YESSnapshot: Non-withdrawable balance BEFORE. Example: Player has $50 bonus, makes $10 bet -> bonus_balance_before = 50
bonus_balance_afternumeric(18)YESSnapshot: Non-withdrawable balance AFTER. Example: Player has $50 bonus, makes $10 bet -> bonus_balance_after = 40
metadatajsonbYESFlexible JSON for additional context (game info, provider data, etc.)
dt_finalizedtimestampYESWhen the transaction reached a final state (completed/cancelled). Set by trigger.
created_attimestampYESCURRENT_TIMESTAMPTransaction creation timestamp
updated_attimestampYESCURRENT_TIMESTAMPLast update timestamp

Transaction Categories

CategoryDescription
depositPlayer purchasing coins or depositing real money
withdrawalPlayer redeeming SC or withdrawing real money
betWager placed on a game
winWinnings from a game
bonusBonus credit (manual or automatic)
adjustmentManual admin adjustment
rewardSystem rewards (daily login, VIP cashback, etc.)
free_spinFree spin credits/winnings

Balance Type Enum

ValueDescription
withdrawableReal/cash balance that can be withdrawn
non-withdrawableBonus balance that requires wagering before withdrawal

Triggers

This table has the most triggers in the system, reflecting its central role:

TriggerFunctionDescription
a0_trigger_prevent_negative_balanceprevent_negative_balanceFirst to fire — prevents transactions that would result in a negative balance
a_update_bonus_amount_on_free_spin_credit_triggerupdate_bonus_amount_on_free_spin_creditUpdates bonus amount on free spin credit transactions
before_transaction_changeupdate_player_balancesUpdates player_balances when a transaction is inserted/updated
after_transaction_deleteupdate_player_balancesReverses balance changes when a transaction is deleted
track_first_deposittrack_first_depositSets first_purchase_date and first_purchase_transaction_id on players
trigger_update_redeemable_scupdate_redeemable_scUpdates redeemable_sc on players for SC wagering tracking
trigger_update_vip_points_and_levelupdate_vip_points_and_levelUpdates user_vip_status points and triggers level changes
trigger_update_withdrawable_balancesupdate_withdrawable_balancesMaintains withdrawable balance tracking
trigger_update_player_bonus_wagering_on_insert/updateupdate_player_bonus_wagering_on_transactionTracks wagering progress against bonus requirements
trigger_update_free_spins_countupdate_free_spins_countTracks free spin usage
trigger_insert_withdrawals / trigger_update_withdrawalsinsert_or_update_withdrawalsSyncs to a withdrawals tracking table
trigger_upsert_deposit_on_insert/updateupsert_depositSyncs to a deposits tracking table
trigger_upsert_payout_on_insert/updateupsert_payoutSyncs to a payouts tracking table
trigger_set_dt_finalizedset_dt_finalizedSets dt_finalized when status changes to a terminal state
tr_transactions_game_sessionstrg_upsert_game_session_from_txCreates/updates game session records from bet/win transactions
z_transfer_bonus_on_last_winning_triggertransfer_bonus_on_last_winningLast to fire — transfers bonus to withdrawable on final winning round

Key Indexes

IndexColumnsNotes
transactions_pkeyidPrimary key
idx_transactions_userplayer_idPlayer transaction history
idx_transactions_player_optimizedplayer_id, created_at DESC, statusOptimized player history queries
idx_transactions_created_atcreated_at DESCTime-based reporting
idx_transactions_categorytransaction_categoryCategory filtering
idx_transactions_deposit_lookupplayer_id, transaction_type, transaction_category, statusPartial: completed deposits
idx_transactions_player_categoryplayer_id, transaction_category, statusPartial: completed deposits/withdrawals
idx_transactions_game_sessiongame_session_idGame round lookups
idx_transactions_external_transaction_idexternal_transaction_idPayment provider reconciliation
idx_transactions_balance_triggerplayer_id, currency_type, balance_type, status, transaction_typePartial: completed — optimizes balance update triggers

Business Rules

  • Trigger names are prefixed with letters (a0_, a_, z_) to control execution order
  • The prevent_negative_balance trigger fires first to ensure no balance goes below zero
  • Balance snapshot fields (*_balance_before/after) create a complete audit trail
  • The balance_type enum separates withdrawable (real money / wagered SC) from non-withdrawable (bonus) funds
  • VIP points are automatically calculated from completed transactions via the update_vip_points_and_level trigger
  • EUR conversion fields enable unified cross-currency reporting