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 <noreply@anthropic.com>
This commit is contained in:
@@ -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`
|
||||
|
||||
Reference in New Issue
Block a user