-- ===================================================================== -- TeeCup — ekte spillformer for frittstående runder (migrasjon 031, -- ADR-039) -- ===================================================================== -- Utvider round.play_format (ADR-038) fra en ren HCP-eksklusjons-etikett -- til å faktisk styre scoringsmodell + scorekort: match/fourball/ -- foursome/greensome/scramble trenger et "sider"-konsept (Beslutning A), -- og delt-ball-formatene (foursome/greensome/scramble) trenger én -- kombinert score PER SIDE per hull i stedet for per spiller -- (Beslutning C) -- gjenbruker samme nullable-nøkkel-mønster som -- org-scopet `hole_score` (migrasjon 001) i stedet for en helt ny tabell. -- ===================================================================== \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')); -- Skins (Beslutning D) -- kun meningsfullt når play_format='skins', -- håndheves i app-laget (samme "kun meningsfullt for..."-mønster som -- resten av round -- ikke en tabellbasert CHECK på tvers av kolonner). ALTER TABLE round ADD COLUMN skins_scoring text CHECK (skins_scoring IN ('net', 'gross')); ALTER TABLE round ADD COLUMN skins_tie_handling text CHECK (skins_tie_handling IN ('carry', 'split')); -- --------------------------------------------------------------------- -- Sider (Beslutning A) -- nøyaktig to per runde for match/fourball/ -- foursome/greensome/scramble, håndhevet i app-laget (samme mønster som -- ADR-011s to-lags-grense for org-turneringer), ikke en DB-constraint. -- --------------------------------------------------------------------- CREATE TABLE round_side ( id uuid PRIMARY KEY DEFAULT gen_random_uuid(), round_id uuid NOT NULL REFERENCES round(id) ON DELETE CASCADE, label text ); CREATE INDEX ON round_side (round_id); ALTER TABLE round_participant ADD COLUMN round_side_id uuid REFERENCES round_side(id) ON DELETE SET NULL; -- Playing Handicap (relativ til motparten via match_play_strokes) -- -- course_handicap_snapshot (eksisterende) er ABSOLUTT og uendret i -- betydning; playing_handicap er den format-avledede enheten, samme -- to-kolonne-mønster som org-scopet match_participant. ALTER TABLE round_participant ADD COLUMN playing_handicap smallint; -- --------------------------------------------------------------------- -- round_hole: nøyaktig ÉN av round_participant_id/round_side_id -- (Beslutning C) -- delt-ball-formater (foursome/greensome/scramble) -- lagrer én rad PER SIDE per hull, ikke per spiller. Individuell-ball- -- formater (slagspill/match/fourball/skins) er uendret -- én rad per -- DELTAKER per hull, som i dag. -- --------------------------------------------------------------------- ALTER TABLE round_hole ALTER COLUMN round_participant_id DROP NOT NULL; ALTER TABLE round_hole ADD COLUMN round_side_id uuid REFERENCES round_side(id) ON DELETE CASCADE; ALTER TABLE round_hole ADD CONSTRAINT round_hole_owner_xor CHECK ( ((round_participant_id IS NOT NULL)::int + (round_side_id IS NOT NULL)::int) = 1 ); ALTER TABLE round_hole DROP CONSTRAINT round_hole_round_participant_id_hole_number_key; CREATE UNIQUE INDEX round_hole_participant_unique ON round_hole (round_participant_id, hole_number) WHERE round_participant_id IS NOT NULL; CREATE UNIQUE INDEX round_hole_side_unique ON round_hole (round_side_id, hole_number) WHERE round_side_id IS NOT NULL; GRANT SELECT, INSERT, UPDATE, DELETE ON round_side TO teecup_app;