teecup/047_shamble_round_and_session.sql
Erol Haagenrud 7ae554062c All eight new turneringsformater have backend + engine complete and scratch-verified — Chapman, Nassau, Københavner, Bingo Bango Bongo, Flaggturnering, Shamble, Money Ball, and High-low-high. Built and tested one format at a time (engine tests → migration → API wiring → scratch verification) exactly per the approved plan:
Verification totals: handicap_engine.py unit tests went from 63 → 98 (all passing), plus 400+ scratch-API checks across the eight formats' test scripts, covering both frittstående runder and the appropriate org-scoped system (team or individual) for each. test_isolation.sql stayed 12/12 throughout — migrations 041–050 are purely additive.

A few real things surfaced and were fixed during testing:

Nassau can be blocked by the existing "match already decided" lock (ADR-012) if the overall 18-hole match closes early — documented as a known v1 limitation, not fixed (would mean loosening an established safety guard).
Københavner's points depend on all 3 players at once, breaking the usual "recompute one participant" pattern — handled with a dedicated recompute path.
High-low-high doesn't fit the existing win/loss/halved match cache, so it gets its own dedicated read endpoint (like Nassau) — verified digit-for-digit against your own worked example ("1-1 etter hull 1", "2-1 til lag 2").
Two missing-column crashes (caught in scratch, never reached anything resembling "done").
2026-07-30 14:54:11 +02:00

31 lines
1.8 KiB
SQL

-- =====================================================================
-- TeeCup — Shamble, migrasjon 047. Sjette av åtte nye turneringsformater
-- denne runden.
--
-- 2-4-manns lag (FLEKSIBEL størrelse, bekreftet av bruker -- ikke fast
-- som de andre formatene). Lagets hullscore = sum av de N beste
-- individuelle resultatene ("beste N av M", N organisator-konfigurerbart
-- via shamble_best_n).
--
-- Frittstående runder: INGEN round_side-involvering (bekreftet av
-- bruker) -- laget ER runden sitt fulle deltakersett, ingen motstander
-- innad. Flere lag som konkurrerer settes opp som separate runder koblet
-- med det allerede byggede flight_group_id-leaderboardet (2026-07-28).
-- Individuell-ball round_hole (som fourball), bare variabel lagstørrelse
-- i stedet for en fast FORMAT_UNIT_SIZE-verdi.
--
-- Org-lagturnering: HER brukes eksisterende to-siders match-struktur (to
-- Shamble-lag møtes) -- variabel lagstørrelse (2-4) i stedet for fast
-- antall.
-- =====================================================================
\set ON_ERROR_STOP on
ALTER TABLE round DROP CONSTRAINT round_play_format_check;
ALTER TABLE round ADD CONSTRAINT round_play_format_check
CHECK (play_format IN ('stroke', 'match', 'skins', 'fourball', 'foursome', 'greensome', 'scramble_2', 'scramble_4', 'stableford', 'chapman', 'copenhagen', 'bbb', 'flag', 'shamble'));
ALTER TABLE round ADD COLUMN shamble_best_n smallint CHECK (shamble_best_n IS NULL OR shamble_best_n >= 1);
ALTER TABLE session DROP CONSTRAINT session_format_check;
ALTER TABLE session ADD CONSTRAINT session_format_check
CHECK (format IN ('singles', 'fourball', 'foursome', 'greensome', 'scramble_2', 'scramble_4', 'chapman', 'shamble'));
ALTER TABLE session ADD COLUMN shamble_best_n smallint CHECK (shamble_best_n IS NULL OR shamble_best_n >= 1);