From 61c3c3f6cf3802729702ff78a3a2989c838a1432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= Date: Mon, 15 Jun 2026 17:37:15 +0200 Subject: [PATCH] fix: add --force flag to sync to clear 2026 data and orphaned teams Needed to recover from duplicate team entries (Bosnia & Herzegovina / USA) that persisted because ON CONFLICT matching is on team IDs, so old rows with wrong team IDs are never updated. --force clears all 2026 data and orphaned teams before re-syncing clean. Co-Authored-By: Claude Sonnet 4.6 --- scripts/sync.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/sync.ts b/scripts/sync.ts index a6e61e8..67ae6c7 100644 --- a/scripts/sync.ts +++ b/scripts/sync.ts @@ -99,6 +99,18 @@ async function run() { // ── Sync 2026 from Wikipedia ─────────────────────────────────────────────── + const force = process.argv.includes('--force') + if (force) { + console.log('--force: clearing 2026 data...') + await db.execute(sql`DELETE FROM goals WHERE match_id IN (SELECT id FROM matches WHERE tournament_year = 2026)`) + await db.execute(sql`DELETE FROM squads WHERE tournament_year = 2026`) + await db.execute(sql`DELETE FROM group_standings WHERE tournament_year = 2026`) + await db.execute(sql`DELETE FROM stadiums WHERE tournament_year = 2026`) + await db.execute(sql`DELETE FROM matches WHERE tournament_year = 2026`) + // Remove orphaned teams that only appeared in 2026 data + await db.execute(sql`DELETE FROM teams WHERE id NOT IN (SELECT team1_id FROM matches UNION SELECT team2_id FROM matches)`) + } + console.log('\nSyncing 2026 from Wikipedia...') await db.execute(sql`