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 |
|---|---|---|---|
id | bigint unsigned | No | Primary key |
game_id | bigint unsigned | No | Parent game |
turn_id | bigint unsigned | No | Parent game turn |
side_code | char(1) | No | Side taking the player turn |
order_in_turn | tinyint | No | Sequence within the game turn |
started_at | datetime(3) | No | Player-turn start |
ended_at | datetime(3) | Yes | Player-turn end |
created_at | datetime(3) | No | Creation timestamp |
updated_at | datetime(3) | No | Last 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.id | Logical many-to-one | Game-wide context |
game_player_turns.turn_id → game_turns.id | Logical many-to-one | Container turn |
game_events.player_turn_id → game_player_turns.id | One-to-many | Events can attach directly to player turn |
game_units.destroyed_in_player_turn_id / below_25_in_player_turn_id → game_player_turns.id | Referenced externally | Scoring-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