game_units

Instantiated unit rows for a specific game side
SQL Gameplay Critical Runtime
game_units

Purpose

Stores the per-game instantiated copy of army units. This is where gameplay state is tracked: destruction, below-25 status, side ownership, and event-linked scoring state.

Role in the system

army_units
   ↓ copied into
game_units
   ↑ referenced by
game_events

Columns

Column Type Null Notes
idbigint unsignedNoPrimary key
game_side_idbigint unsignedNoOwning game side
source_unit_idbigint unsignedYesOriginal army_units source row
namevarchar(200)NoSnapshot unit name
unit_typevarchar(100)YesSnapshot unit type
pointsintNoSnapshot points
quantityintNoSnapshot quantity
notesvarchar(500)YesSnapshot notes/options
is_generaltinyint(1)NoGeneral flag
is_bsbtinyint(1)NoBSB flag
has_standardtinyint(1)NoBanner/standard flag
sort_orderintNoDisplay order
created_atdatetime(3)NoCreation timestamp
updated_atdatetime(3)NoLast update timestamp
destroyed_atdatetime(3)YesUnit destroyed marker
destroyed_in_event_idbigint unsignedYesDestroying event reference (soft link)
destroyed_by_side_codechar(1)YesScoring side for destruction
destroyed_in_player_turn_idbigint unsignedYesPlayer turn when destroyed
below_25_atdatetime(3)YesBelow-25 marker
below_25_in_event_idbigint unsignedYesEvent reference for below-25
below_25_by_side_codechar(1)YesScoring side for below-25
below_25_in_player_turn_idbigint unsignedYesPlayer turn for below-25
master_unit_idintNoCopied canonical master unit identifier, default -1

Keys and indexes

  • PRIMARY KEY (id)
  • KEY ix_game_units_side (game_side_id)
  • KEY ix_game_units_side_sort (game_side_id, sort_order, id)
  • KEY ix_game_units_source (source_unit_id)
  • idx_game_units_destroyed (destroyed_at)
  • idx_game_units_master_unit_id (master_unit_id)
  • idx_game_units_below25_at (below_25_at)
  • idx_game_units_below25_event (below_25_in_event_id)
  • idx_game_units_destroyed_at (destroyed_at)

Foreign keys

  • fk_game_units_side: game_units.game_side_id → game_sides.id ON DELETE CASCADE
  • fk_game_units_source: game_units.source_unit_id → army_units.id ON DELETE SET NULL

Relationships

Relationship Type Notes
game_units.game_side_id → game_sides.idMany-to-oneUnit belongs to one game side
game_units.source_unit_id → army_units.idOptional many-to-oneOriginal army unit snapshot source
game_events.unit_id → game_units.idOne-to-manyEvents attach to game units

Gameplay state model

This table stores persistent in-game state rather than recalculating everything from events at read time. Key tracked states include:

  • Destroyed
  • Below 25%
  • Who scored the state
  • Which event and player turn caused the state

Used by

  • Game start/setup side flows that instantiate units
  • Event create/delete logic
  • Play-state calculation and UI
  • Game breakdown and standings context

Design notes

  • This is effectively a snapshot-plus-state table
  • State is denormalized intentionally for fast gameplay reads
  • Soft links such as destroyed_in_event_id are not enforced by FK constraints
  • master_unit_id is preserved for canonical reporting/debugging even though source_unit_id points to army_units

Risks

  • Denormalized state can drift if event creation/deletion logic is incorrect
  • Missing FKs on destroyed/below25 reference fields mean consistency relies on application logic
  • This table is central to scoring correctness

Recommended future improvements

  • Document state-transition rules explicitly
  • Consider whether some reference fields should have FKs if migration risk is acceptable
  • Add integrity diagnostics/admin tooling for state/event reconciliation