game_player_turns

Per-side turn sequence inside each game turn
SQL Gameplay Turn Model
game_player_turns

Purpose

Stores the per-side player turns nested inside a game turn. This table is essential for attributing events, destruction state, and scoring to the correct side and sequence step.

Columns

Column Type Null Notes
idbigint unsignedNoPrimary key
game_idbigint unsignedNoParent game
turn_idbigint unsignedNoParent game turn
side_codechar(1)NoSide taking the player turn
order_in_turntinyintNoSequence within the game turn
started_atdatetime(3)NoPlayer-turn start
ended_atdatetime(3)YesPlayer-turn end
created_atdatetime(3)NoCreation timestamp
updated_atdatetime(3)NoLast update timestamp

Keys and indexes

  • PRIMARY KEY (id)
  • KEY idx_gpt_game_turn (game_id, turn_id)
  • KEY idx_gpt_active (game_id, ended_at)

Foreign keys

The schema currently has no explicit foreign keys on turn_id or game_id here, even though they are logically tied to game_turns and games.

Relationships

Relationship Type Notes
game_player_turns.game_id → games.idLogical many-to-oneGame-wide context
game_player_turns.turn_id → game_turns.idLogical many-to-oneContainer turn
game_events.player_turn_id → game_player_turns.idOne-to-manyEvents can attach directly to player turn
game_units.destroyed_in_player_turn_id / below_25_in_player_turn_id → game_player_turns.idReferenced externallyScoring-state attribution

Used by

  • Player-turn start/end flows
  • Event creation that requires an active player turn
  • Per-turn scoring and state attribution

Design notes

  • This table is central to the newer turn-structure refactor
  • Open player turn is represented by ended_at IS NULL
  • The schema relies on application logic for integrity between game, turn, and side order

Risks

  • Lack of explicit foreign keys increases reliance on application correctness
  • No uniqueness rule currently prevents duplicate (turn_id, side_code, order_in_turn) combinations
  • Active-player-turn uniqueness is not enforced by DB constraint

Recommended future improvements

  • Add explicit FK constraints if migration risk is manageable
  • Consider unique constraint for per-turn ordering
  • Document invariants for active player-turn management