Skip to content

Commit a61a493

Browse files
committed
bug: fix double elmintination bye handling
1 parent 9eba6c2 commit a61a493

2 files changed

Lines changed: 2 additions & 39 deletions

File tree

hasura/functions/tournaments/schedule_tournament_match.sql

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,6 @@ CREATE OR REPLACE FUNCTION public.schedule_tournament_match(bracket public.tourn
2626
RETURN NULL;
2727
END IF;
2828

29-
-- Special handling for losers-bracket matches where we may effectively have a bye
30-
IF COALESCE(bracket.path, 'WB') = 'LB' THEN
31-
-- Exactly one team present: decide whether a second team can still appear
32-
IF bracket.tournament_team_id_1 IS NULL OR bracket.tournament_team_id_2 IS NULL THEN
33-
FOR feeder IN
34-
SELECT tb.*
35-
FROM tournament_brackets tb
36-
WHERE tb.parent_bracket_id = bracket.id
37-
OR tb.loser_parent_bracket_id = bracket.id
38-
LOOP
39-
IF feeder.tournament_team_id_1 IS NOT NULL OR feeder.tournament_team_id_2 IS NOT NULL THEN
40-
feeders_with_team := feeders_with_team + 1;
41-
END IF;
42-
END LOOP;
43-
44-
-- If we don't have at least one team in both feeder matches,
45-
-- treat this as an effective bye and auto-advance the existing team.
46-
IF feeders_with_team < 2 THEN
47-
winner_id := COALESCE(bracket.tournament_team_id_1, bracket.tournament_team_id_2);
48-
49-
IF winner_id IS NOT NULL AND bracket.parent_bracket_id IS NOT NULL THEN
50-
update tournament_brackets
51-
SET finished = true
52-
WHERE id = bracket.id;
53-
54-
PERFORM public.assign_team_to_bracket_slot(bracket.parent_bracket_id, winner_id);
55-
END IF;
56-
57-
RETURN NULL;
58-
END IF;
59-
END IF;
60-
END IF;
61-
6229
-- For all other cases, we require two teams to schedule a match
6330
IF bracket.tournament_team_id_1 IS NULL OR bracket.tournament_team_id_2 IS NULL THEN
6431
RETURN NULL;

hasura/triggers/tournament_brackets.sql

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,9 @@ BEGIN
2626
RETURN NEW; -- Skip scheduling for round > 1 in RoundRobin
2727
END IF;
2828

29-
-- Normal case: schedule when both teams are present
29+
raise notice 'Scheduling match for bracket %', NEW.id;
3030
IF NEW.tournament_team_id_1 IS NOT NULL AND NEW.tournament_team_id_2 IS NOT NULL THEN
31-
PERFORM schedule_tournament_match(NEW);
32-
-- Losers bracket special case: allow schedule_tournament_match to decide if this should be a bye
33-
ELSIF COALESCE(NEW.path, 'WB') = 'LB' AND
34-
(NEW.tournament_team_id_1 IS NOT NULL OR NEW.tournament_team_id_2 IS NOT NULL) THEN
35-
PERFORM schedule_tournament_match(NEW);
31+
PERFORM schedule_tournament_match(NEW);
3632
END IF;
3733
END IF;
3834

0 commit comments

Comments
 (0)