fix: drop provisional knockout matches where teams haven't yet advanced

Wikipedia pre-fills QF/SF/Final bracket slots with projected team names
before the preceding round is complete. After each sync, delete any
unplayed knockout match where either team still has an unplayed match in
an earlier round — these entries are speculative and shouldn't be shown
as confirmed fixtures.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-07 18:04:53 +02:00
co-authored by Claude Sonnet 4.6
parent e3dd53c40c
commit c5f30b4eaf
+32
View File
@@ -287,6 +287,38 @@ async function run() {
WHERE year = 2026
`)
// Remove provisional knockout matches: if a team still has an unplayed match in an
// earlier round, any future-round match involving that team is not yet confirmed.
// Wikipedia pre-fills bracket slots speculatively before the preceding round finishes.
const deletedProvisional = await db.execute(sql`
WITH provisional AS (
SELECT DISTINCT m.id
FROM matches m
JOIN matches prev ON prev.tournament_year = m.tournament_year
AND prev.group_name IS NULL
AND prev.score_ft_home IS NULL
AND prev.id != m.id
AND (
CASE prev.round WHEN 'Round of 32' THEN 1 WHEN 'Round of 16' THEN 2
WHEN 'Quarter-finals' THEN 3 WHEN 'Semi-finals' THEN 4
WHEN 'Third-place play-off' THEN 5 WHEN 'Final' THEN 6 ELSE 99 END
<
CASE m.round WHEN 'Round of 32' THEN 1 WHEN 'Round of 16' THEN 2
WHEN 'Quarter-finals' THEN 3 WHEN 'Semi-finals' THEN 4
WHEN 'Third-place play-off' THEN 5 WHEN 'Final' THEN 6 ELSE 99 END
)
AND (prev.team1_id = m.team1_id OR prev.team2_id = m.team1_id
OR prev.team1_id = m.team2_id OR prev.team2_id = m.team2_id)
WHERE m.tournament_year = 2026
AND m.group_name IS NULL
AND m.is_quali_playoff = false
AND m.score_ft_home IS NULL
)
DELETE FROM matches WHERE id IN (SELECT id FROM provisional) RETURNING id
`)
if (deletedProvisional.length > 0)
console.log(` Removed ${deletedProvisional.length} provisional knockout match(es)`)
console.log(`${matchCount} matches, ${goalCount} goals`)
console.log('\n✅ Sync complete!')
await client.end()