-- Upgrade to DATETIME(3) for millisecond precision in race timing.

ALTER TABLE `ranking_records`
  MODIFY COLUMN `captured_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3);

ALTER TABLE `stages`
  MODIFY COLUMN `start_time` DATETIME(3) NULL DEFAULT NULL;

-- Store elapsed time as milliseconds instead of seconds for precision.
ALTER TABLE `rankings`
  MODIFY COLUMN `rank_time_seconds` DOUBLE NULL DEFAULT NULL;

-- Explicit timing mode per stage (replaces the start_time heuristic).
-- mass_start: all runners timed from stage start_time.
-- deferred:   each runner timed from their own first crossing.
ALTER TABLE `stages`
  ADD COLUMN `timing_mode` ENUM('mass_start', 'deferred') NOT NULL DEFAULT 'mass_start' AFTER `type`;
