@@ -766,11 +766,11 @@ BEGIN
766766 END LOOP;
767767
768768 -- Create brackets (semifinals + final)
769- INSERT INTO tournament_brackets (id, tournament_stage_id, tournament_team_id_1, tournament_team_id_2, round, match_number, " group" , path , finished)
769+ INSERT INTO tournament_brackets (id, tournament_stage_id, tournament_team_id_1, tournament_team_id_2, round, match_number, " group" , path , finished, parent_bracket_id )
770770 VALUES
771- (t1_bracket_sf1, t1_stage_id, t1_team_ids[1 ], t1_team_ids[4 ], 1 , 1 , 1 , ' WB' , true),
772- (t1_bracket_sf2, t1_stage_id, t1_team_ids[2 ], t1_team_ids[3 ], 1 , 2 , 1 , ' WB' , true),
773- (t1_bracket_final, t1_stage_id, t1_team_ids[1 ], t1_team_ids[2 ], 2 , 1 , 1 , ' WB' , true);
771+ (t1_bracket_sf1, t1_stage_id, t1_team_ids[1 ], t1_team_ids[4 ], 1 , 1 , 1 , ' WB' , true, t1_bracket_final ),
772+ (t1_bracket_sf2, t1_stage_id, t1_team_ids[2 ], t1_team_ids[3 ], 1 , 2 , 1 , ' WB' , true, t1_bracket_final ),
773+ (t1_bracket_final, t1_stage_id, t1_team_ids[1 ], t1_team_ids[2 ], 2 , 1 , 1 , ' WB' , true, NULL );
774774
775775 -- Create matches linked to finished brackets
776776 -- SF1: T1 vs T4 → T1 wins, SF2: T2 vs T3 → T2 wins, Final: T1 vs T2 → T1 wins
@@ -934,7 +934,9 @@ BEGIN
934934 t2_team_ids uuid[];
935935 t2_bracket_r1m1 uuid := gen_random_uuid();
936936 t2_bracket_r1m2 uuid := gen_random_uuid();
937- t2_bracket_r1m3 uuid := gen_random_uuid();
937+ t2_bracket_r2m1 uuid := gen_random_uuid();
938+ t2_bracket_r2m2 uuid := gen_random_uuid();
939+ t2_bracket_final uuid := gen_random_uuid();
938940 BEGIN
939941 INSERT INTO match_options (id, overtime, knife_round, mr, best_of, map_veto, type, map_pool_id, lobby_access)
940942 VALUES (t2_options_id, true, true, 12 , 1 , true, ' Competitive' , comp_map_pool_id, ' Private' );
@@ -979,26 +981,23 @@ BEGIN
979981 END LOOP;
980982 END LOOP;
981983
982- -- First round brackets (3 matches for 6 teams )
983- INSERT INTO tournament_brackets (id, tournament_stage_id, tournament_team_id_1, tournament_team_id_2, round, match_number, " group" , path , finished)
984+ -- Round 1 brackets (seeds 3v6, 4v5 — top 2 seeds get byes to R2 )
985+ INSERT INTO tournament_brackets (id, tournament_stage_id, tournament_team_id_1, tournament_team_id_2, round, match_number, " group" , path , finished, parent_bracket_id )
984986 VALUES
985- (t2_bracket_r1m1, t2_stage_id, t2_team_ids[1 ], t2_team_ids[6 ], 1 , 1 , 1 , ' WB' , true);
986- INSERT INTO tournament_brackets (id, tournament_stage_id, tournament_team_id_1, tournament_team_id_2, round, match_number, " group" , path , finished)
987- VALUES
988- (t2_bracket_r1m2, t2_stage_id, t2_team_ids[2 ], t2_team_ids[5 ], 1 , 2 , 1 , ' WB' , false),
989- (t2_bracket_r1m3, t2_stage_id, t2_team_ids[3 ], t2_team_ids[4 ], 1 , 3 , 1 , ' WB' , false);
987+ (t2_bracket_r1m1, t2_stage_id, t2_team_ids[3 ], t2_team_ids[6 ], 1 , 1 , 1 , ' WB' , true, t2_bracket_r2m1),
988+ (t2_bracket_r1m2, t2_stage_id, t2_team_ids[4 ], t2_team_ids[5 ], 1 , 2 , 1 , ' WB' , false, t2_bracket_r2m2);
990989
991- -- Semifinal brackets (placeholders )
992- INSERT INTO tournament_brackets (tournament_stage_id, tournament_team_id_1, round, match_number, " group" , path , finished)
990+ -- Semifinal brackets (seed 1 pre-placed in R2M1, seed 2 pre-placed in R2M2 )
991+ INSERT INTO tournament_brackets (id, tournament_stage_id, tournament_team_id_1, round, match_number, " group" , path , finished, parent_bracket_id )
993992 VALUES
994- (t2_stage_id, t2_team_ids[1 ], 2 , 1 , 1 , ' WB' , false),
995- (t2_stage_id, NULL , 2 , 2 , 1 , ' WB' , false);
993+ (t2_bracket_r2m1, t2_stage_id, t2_team_ids[1 ], 2 , 1 , 1 , ' WB' , false, t2_bracket_final ),
994+ (t2_bracket_r2m2, t2_stage_id, t2_team_ids[ 2 ] , 2 , 2 , 1 , ' WB' , false, t2_bracket_final );
996995
997996 -- Final bracket
998- INSERT INTO tournament_brackets (tournament_stage_id, round, match_number, " group" , path , finished)
999- VALUES (t2_stage_id, 3 , 1 , 1 , ' WB' , false);
997+ INSERT INTO tournament_brackets (id, tournament_stage_id, round, match_number, " group" , path , finished)
998+ VALUES (t2_bracket_final, t2_stage_id, 3 , 1 , 1 , ' WB' , false);
1000999
1001- -- Create match for the one finished bracket (R1 M1: T1 vs T6, T1 wins)
1000+ -- Create match for the one finished bracket (R1 M1: T3 vs T6, T3 Crimson Wolves wins)
10021001 DECLARE
10031002 t2_mid uuid := gen_random_uuid();
10041003 t2_moid uuid := gen_random_uuid();
@@ -1012,7 +1011,7 @@ BEGIN
10121011 VALUES (t2_moid, true, true, 12 , 1 , true, ' Competitive' , comp_map_pool_id, ' Private' , 115 );
10131012
10141013 INSERT INTO match_lineups (id, team_id, team_name) VALUES
1015- (t2_l1id, team_ids[1 ], team_names[1 ]),
1014+ (t2_l1id, team_ids[3 ], team_names[3 ]),
10161015 (t2_l2id, team_ids[6 ], team_names[6 ]);
10171016
10181017 INSERT INTO matches (id, status, match_options_id, lineup_1_id, lineup_2_id,
@@ -1023,7 +1022,7 @@ BEGIN
10231022
10241023 FOR j IN 1 ..5 LOOP
10251024 INSERT INTO match_lineup_players (match_lineup_id, steam_id, captain, checked_in) VALUES
1026- (t2_l1id, p_steam_ids[(1 - 1 ) * 5 + j], j = 1 , true),
1025+ (t2_l1id, p_steam_ids[(3 - 1 ) * 5 + j], j = 1 , true),
10271026 (t2_l2id, p_steam_ids[(6 - 1 ) * 5 + j], j = 1 , true);
10281027 END LOOP;
10291028
@@ -1048,7 +1047,7 @@ BEGIN
10481047 t2_mdate - interval ' 10 minutes' + (interval ' 30 seconds' * ban_n));
10491048 END;
10501049
1051- -- Generate rounds and kills (T1 wins 13-8)
1050+ -- Generate rounds and kills (T3 Crimson Wolves wins 13-8)
10521051 v_t1_wins := 0 ; v_t2_wins := 0 ;
10531052 FOR round_num IN 1 ..(t2_l1s + t2_l2s) LOOP
10541053 IF v_t1_wins * (t2_l1s + t2_l2s) < round_num * t2_l1s AND v_t1_wins < t2_l1s THEN
@@ -1074,9 +1073,9 @@ BEGIN
10741073 attacker_steam_id, attacker_team, attacked_steam_id, attacked_team, attacked_location,
10751074 " with" , hitgroup, headshot, time )
10761075 VALUES (t2_mid, t2_mmid, round_num,
1077- p_steam_ids[(CASE WHEN k % 2 = 1 THEN 1 ELSE 6 END - 1 ) * 5 + ((k - 1 ) % 5 ) + 1 ],
1076+ p_steam_ids[(CASE WHEN k % 2 = 1 THEN 3 ELSE 6 END - 1 ) * 5 + ((k - 1 ) % 5 ) + 1 ],
10781077 CASE WHEN (k % 2 = 1 ) = (round_num <= 12 ) THEN ' CT' ELSE ' TERRORIST' END,
1079- p_steam_ids[(CASE WHEN k % 2 = 1 THEN 6 ELSE 1 END - 1 ) * 5 + ((k + round_num) % 5 ) + 1 ],
1078+ p_steam_ids[(CASE WHEN k % 2 = 1 THEN 6 ELSE 3 END - 1 ) * 5 + ((k + round_num) % 5 ) + 1 ],
10801079 CASE WHEN (k % 2 = 1 ) = (round_num <= 12 ) THEN ' TERRORIST' ELSE ' CT' END,
10811080 ' BombsiteA' , weapons[((round_num + k) % array_length(weapons, 1 )) + 1 ],
10821081 CASE WHEN (round_num + k) % 3 = 0 THEN ' head' ELSE hitgroups[((k + round_num) % 6 ) + 2 ] END,
@@ -1088,7 +1087,7 @@ BEGIN
10881087 -- Utility events
10891088 DECLARE
10901089 ut timestamptz ;
1091- fp1 int := (1 - 1 ) * 5 + ((round_num + 1 ) % 5 ) + 1 ;
1090+ fp1 int := (3 - 1 ) * 5 + ((round_num + 1 ) % 5 ) + 1 ;
10921091 fp2 int := (6 - 1 ) * 5 + ((round_num + 2 ) % 5 ) + 1 ;
10931092 BEGIN
10941093 ut := t2_mdate + (interval ' 2 minutes' * round_num) + interval ' 40 seconds' ;
@@ -1104,19 +1103,19 @@ BEGIN
11041103 VALUES (t2_mmid, p_steam_ids[fp2], ut, t2_mid, round_num, ' Flash' ) ON CONFLICT DO NOTHING;
11051104 INSERT INTO player_flashes (match_map_id, time , attacker_steam_id, attacked_steam_id, match_id, round, duration, team_flash)
11061105 VALUES (t2_mmid, ut + interval ' 1 second' , p_steam_ids[fp2],
1107- p_steam_ids[(1 - 1 ) * 5 + ((round_num + 4 ) % 5 ) + 1 ],
1106+ p_steam_ids[(3 - 1 ) * 5 + ((round_num + 4 ) % 5 ) + 1 ],
11081107 t2_mid, round_num, 1 .5 + ((round_num + 1 ) % 3 )::numeric * 0 .5 , false) ON CONFLICT DO NOTHING;
11091108
11101109 IF round_num % 3 = 0 THEN
11111110 INSERT INTO player_flashes (match_map_id, time , attacker_steam_id, attacked_steam_id, match_id, round, duration, team_flash)
11121111 VALUES (t2_mmid, ut + interval ' 2 seconds' , p_steam_ids[fp1],
1113- p_steam_ids[(1 - 1 ) * 5 + ((round_num + 2 ) % 5 ) + 1 ],
1112+ p_steam_ids[(3 - 1 ) * 5 + ((round_num + 2 ) % 5 ) + 1 ],
11141113 t2_mid, round_num, 0 .8 + (round_num % 2 )::numeric * 0 .4 , true) ON CONFLICT DO NOTHING;
11151114 END IF;
11161115
11171116 ut := t2_mdate + (interval ' 2 minutes' * round_num) + interval ' 35 seconds' ;
11181117 INSERT INTO player_utility (match_map_id, attacker_steam_id, time , match_id, round, type)
1119- VALUES (t2_mmid, p_steam_ids[(1 - 1 ) * 5 + ((round_num + 3 ) % 5 ) + 1 ], ut, t2_mid, round_num, ' Smoke' ) ON CONFLICT DO NOTHING;
1118+ VALUES (t2_mmid, p_steam_ids[(3 - 1 ) * 5 + ((round_num + 3 ) % 5 ) + 1 ], ut, t2_mid, round_num, ' Smoke' ) ON CONFLICT DO NOTHING;
11201119
11211120 ut := t2_mdate + (interval ' 2 minutes' * round_num) + interval ' 55 seconds' ;
11221121 IF round_num % 2 = 0 THEN
@@ -1126,15 +1125,15 @@ BEGIN
11261125 attacked_steam_id, attacked_team, attacked_location, " with" , damage, damage_armor, health, armor, hitgroup, time )
11271126 VALUES (t2_mid, t2_mmid, round_num,
11281127 p_steam_ids[(6 - 1 ) * 5 + (round_num % 5 ) + 1 ], CASE WHEN round_num <= 12 THEN ' TERRORIST' ELSE ' CT' END,
1129- p_steam_ids[(1 - 1 ) * 5 + ((round_num + 1 ) % 5 ) + 1 ], CASE WHEN round_num <= 12 THEN ' CT' ELSE ' TERRORIST' END,
1128+ p_steam_ids[(3 - 1 ) * 5 + ((round_num + 1 ) % 5 ) + 1 ], CASE WHEN round_num <= 12 THEN ' CT' ELSE ' TERRORIST' END,
11301129 ' BombsiteA' , ' hegrenade' , 15 + (round_num % 30 ), 0 , 85 - (round_num % 30 ), 100 , ' chest' , ut + interval ' 0.3 seconds' );
11311130 ELSE
11321131 INSERT INTO player_utility (match_map_id, attacker_steam_id, time , match_id, round, type)
1133- VALUES (t2_mmid, p_steam_ids[(1 - 1 ) * 5 + ((round_num + 4 ) % 5 ) + 1 ], ut, t2_mid, round_num, ' Molotov' ) ON CONFLICT DO NOTHING;
1132+ VALUES (t2_mmid, p_steam_ids[(3 - 1 ) * 5 + ((round_num + 4 ) % 5 ) + 1 ], ut, t2_mid, round_num, ' Molotov' ) ON CONFLICT DO NOTHING;
11341133 INSERT INTO player_damages (match_id, match_map_id, round, attacker_steam_id, attacker_team,
11351134 attacked_steam_id, attacked_team, attacked_location, " with" , damage, damage_armor, health, armor, hitgroup, time )
11361135 VALUES (t2_mid, t2_mmid, round_num,
1137- p_steam_ids[(1 - 1 ) * 5 + ((round_num + 4 ) % 5 ) + 1 ], CASE WHEN round_num <= 12 THEN ' CT' ELSE ' TERRORIST' END,
1136+ p_steam_ids[(3 - 1 ) * 5 + ((round_num + 4 ) % 5 ) + 1 ], CASE WHEN round_num <= 12 THEN ' CT' ELSE ' TERRORIST' END,
11381137 p_steam_ids[(6 - 1 ) * 5 + ((round_num + 2 ) % 5 ) + 1 ], CASE WHEN round_num <= 12 THEN ' TERRORIST' ELSE ' CT' END,
11391138 ' BombsiteA' , ' inferno' , 10 + (round_num % 25 ), 0 , 90 - (round_num % 25 ), 100 , ' chest' , ut + interval ' 0.5 seconds' );
11401139 END IF;
@@ -1144,7 +1143,7 @@ BEGIN
11441143 UPDATE tournament_brackets SET match_id = t2_mid WHERE id = t2_bracket_r1m1;
11451144 END;
11461145
1147- -- R1 M2: T2 vs T5 (Live, currently in progress)
1146+ -- R1 M2: T4 vs T5 (Live, currently in progress — Dark Phoenix vs Echo Storm )
11481147 DECLARE
11491148 t2_m2_id uuid := gen_random_uuid();
11501149 t2_m2_oid uuid := gen_random_uuid();
@@ -1158,7 +1157,7 @@ BEGIN
11581157 VALUES (t2_m2_oid, true, true, 12 , 1 , true, ' Competitive' , comp_map_pool_id, ' Private' , 115 );
11591158
11601159 INSERT INTO match_lineups (id, team_id, team_name) VALUES
1161- (t2_m2_l1id, team_ids[2 ], team_names[2 ]),
1160+ (t2_m2_l1id, team_ids[4 ], team_names[4 ]),
11621161 (t2_m2_l2id, team_ids[5 ], team_names[5 ]);
11631162
11641163 INSERT INTO matches (id, status, match_options_id, lineup_1_id, lineup_2_id,
@@ -1168,7 +1167,7 @@ BEGIN
11681167
11691168 FOR j IN 1 ..5 LOOP
11701169 INSERT INTO match_lineup_players (match_lineup_id, steam_id, captain, checked_in) VALUES
1171- (t2_m2_l1id, p_steam_ids[(2 - 1 ) * 5 + j], j = 1 , true),
1170+ (t2_m2_l1id, p_steam_ids[(4 - 1 ) * 5 + j], j = 1 , true),
11721171 (t2_m2_l2id, p_steam_ids[(5 - 1 ) * 5 + j], j = 1 , true);
11731172 END LOOP;
11741173
@@ -1218,9 +1217,9 @@ BEGIN
12181217 attacker_steam_id, attacker_team, attacked_steam_id, attacked_team, attacked_location,
12191218 " with" , hitgroup, headshot, time )
12201219 VALUES (t2_m2_id, t2_m2_mmid, round_num,
1221- p_steam_ids[(CASE WHEN k % 2 = 1 THEN 2 ELSE 5 END - 1 ) * 5 + ((k - 1 ) % 5 ) + 1 ],
1220+ p_steam_ids[(CASE WHEN k % 2 = 1 THEN 4 ELSE 5 END - 1 ) * 5 + ((k - 1 ) % 5 ) + 1 ],
12221221 CASE WHEN (k % 2 = 1 ) = (round_num <= 12 ) THEN ' CT' ELSE ' TERRORIST' END,
1223- p_steam_ids[(CASE WHEN k % 2 = 1 THEN 5 ELSE 2 END - 1 ) * 5 + ((k + round_num) % 5 ) + 1 ],
1222+ p_steam_ids[(CASE WHEN k % 2 = 1 THEN 5 ELSE 4 END - 1 ) * 5 + ((k + round_num) % 5 ) + 1 ],
12241223 CASE WHEN (k % 2 = 1 ) = (round_num <= 12 ) THEN ' TERRORIST' ELSE ' CT' END,
12251224 ' BombsiteA' , weapons[((round_num + k) % array_length(weapons, 1 )) + 1 ],
12261225 CASE WHEN (round_num + k) % 3 = 0 THEN ' head' ELSE hitgroups[((k + round_num) % 6 ) + 2 ] END,
@@ -1233,37 +1232,6 @@ BEGIN
12331232 UPDATE tournament_brackets SET match_id = t2_m2_id WHERE id = t2_bracket_r1m2;
12341233 END;
12351234
1236- -- R1 M3: T3 vs T4 (Scheduled, upcoming)
1237- DECLARE
1238- t2_m3_id uuid := gen_random_uuid();
1239- t2_m3_oid uuid := gen_random_uuid();
1240- t2_m3_l1id uuid := gen_random_uuid();
1241- t2_m3_l2id uuid := gen_random_uuid();
1242- t2_m3_date timestamptz := now() + interval ' 2 hours' ;
1243- BEGIN
1244- INSERT INTO match_options (id, overtime, knife_round, mr, best_of, map_veto, type, map_pool_id, lobby_access, tv_delay)
1245- VALUES (t2_m3_oid, true, true, 12 , 1 , true, ' Competitive' , comp_map_pool_id, ' Private' , 115 );
1246-
1247- INSERT INTO match_lineups (id, team_id, team_name) VALUES
1248- (t2_m3_l1id, team_ids[3 ], team_names[3 ]),
1249- (t2_m3_l2id, team_ids[4 ], team_names[4 ]);
1250-
1251- INSERT INTO matches (id, status, match_options_id, lineup_1_id, lineup_2_id,
1252- created_at, scheduled_at, started_at, ended_at, winning_lineup_id)
1253- VALUES (t2_m3_id, ' Scheduled' , t2_m3_oid, t2_m3_l1id, t2_m3_l2id,
1254- now(), t2_m3_date, NULL , NULL , NULL );
1255-
1256- FOR j IN 1 ..5 LOOP
1257- INSERT INTO match_lineup_players (match_lineup_id, steam_id, captain, checked_in) VALUES
1258- (t2_m3_l1id, p_steam_ids[(3 - 1 ) * 5 + j], j = 1 , false),
1259- (t2_m3_l2id, p_steam_ids[(4 - 1 ) * 5 + j], j = 1 , false);
1260- END LOOP;
1261-
1262- INSERT INTO match_maps (id, match_id, map_id, " order" , status, lineup_1_side, lineup_2_side, started_at, ended_at, winning_lineup_id)
1263- VALUES (gen_random_uuid(), t2_m3_id, map_ids[3 ], 1 , ' Scheduled' , ' CT' , ' TERRORIST' , NULL , NULL , NULL );
1264-
1265- UPDATE tournament_brackets SET match_id = t2_m3_id WHERE id = t2_bracket_r1m3;
1266- END;
12671235 END;
12681236
12691237 -- Tournament 3: RegistrationOpen
0 commit comments