Skip to content

Commit 7e963f4

Browse files
committed
fix: use per-round match numbering for Round Robin brackets
match_number was a global counter (1-28 for 8 teams), causing badges to show "Round 2 Match 5" instead of "Round 2 Match 1". Now uses the per-round loop variable, consistent with SE and DE bracket types. Safe for multi-stage tournaments since RR advancement uses standings.
1 parent 60205f8 commit 7e963f4

1 file changed

Lines changed: 19 additions & 23 deletions

File tree

hasura/functions/tournaments/create_round_robin_matches.sql

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ DECLARE
1414
team_count int;
1515
round_count int;
1616
matches_per_round int;
17-
match_counter int;
17+
1818
round_num int;
1919
i int;
2020
k int;
@@ -58,8 +58,6 @@ BEGIN
5858
RAISE NOTICE 'Creating round robin matches for % teams: % rounds, % matches per round, starting at round %',
5959
team_count, round_count, matches_per_round, _start_round;
6060

61-
match_counter := 0;
62-
6361
-- Generate round robin matches using rotating algorithm
6462
FOR round_num IN 1..round_count LOOP
6563
IF use_team_ids THEN
@@ -110,37 +108,35 @@ BEGIN
110108
team_2_id := NULL;
111109
END IF;
112110

113-
match_counter := match_counter + 1;
114-
115111
INSERT INTO tournament_brackets (
116-
round,
117-
tournament_stage_id,
118-
match_number,
119-
"group",
120-
team_1_seed,
121-
team_2_seed,
112+
round,
113+
tournament_stage_id,
114+
match_number,
115+
"group",
116+
team_1_seed,
117+
team_2_seed,
122118
path,
123119
tournament_team_id_1,
124120
tournament_team_id_2
125121
)
126122
VALUES (
127-
_start_round + round_num - 1,
128-
_stage_id,
129-
match_counter,
130-
_group,
131-
team_1_seed,
132-
team_2_seed,
123+
_start_round + round_num - 1,
124+
_stage_id,
125+
i,
126+
_group,
127+
team_1_seed,
128+
team_2_seed,
133129
'WB',
134130
team_1_id,
135131
team_2_id
136132
);
137-
133+
138134
IF use_team_ids THEN
139-
RAISE NOTICE 'Created match %: round %, team % vs team %',
140-
match_counter, _start_round + round_num - 1, team_1_id, team_2_id;
135+
RAISE NOTICE 'Created match %: round %, team % vs team %',
136+
i, _start_round + round_num - 1, team_1_id, team_2_id;
141137
ELSE
142-
RAISE NOTICE 'Created match %: round %, seed % vs seed %',
143-
match_counter, _start_round + round_num - 1, team_1_seed, team_2_seed;
138+
RAISE NOTICE 'Created match %: round %, seed % vs seed %',
139+
i, _start_round + round_num - 1, team_1_seed, team_2_seed;
144140
END IF;
145141
END LOOP;
146142
END LOOP;
@@ -161,7 +157,7 @@ BEGIN
161157
END LOOP;
162158
END IF;
163159

164-
RAISE NOTICE 'Created % round robin matches starting at round %', match_counter, _start_round;
160+
RAISE NOTICE 'Created % round robin matches starting at round %', round_count * matches_per_round, _start_round;
165161
END;
166162
$$;
167163

0 commit comments

Comments
 (0)