From 5b2407bec12d221dea3783b4590250cfd46c3310 Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Mon, 23 Mar 2026 21:16:35 -0700 Subject: [PATCH] Fix upsert standings no-op: use EXCLUDED pseudo-table for conflict update Drizzle's onConflictDoUpdate set block was referencing the existing table columns instead of the incoming values, causing every sync to silently overwrite records with their own current data (no-op). Fixes #211 Co-Authored-By: Claude Sonnet 4.6 --- app/models/regular-season-standings.ts | 40 +++++++++++++------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/app/models/regular-season-standings.ts b/app/models/regular-season-standings.ts index b332455..3b867ee 100644 --- a/app/models/regular-season-standings.ts +++ b/app/models/regular-season-standings.ts @@ -1,6 +1,6 @@ import { database } from "~/database/context"; import * as schema from "~/database/schema"; -import { eq, and, max } from "drizzle-orm"; +import { eq, and, max, sql } from "drizzle-orm"; export interface UpsertRegularSeasonStandingData { participantId: string; @@ -73,25 +73,25 @@ export async function upsertRegularSeasonStandings( schema.regularSeasonStandings.sportsSeasonId, ], set: { - wins: schema.regularSeasonStandings.wins, - losses: schema.regularSeasonStandings.losses, - otLosses: schema.regularSeasonStandings.otLosses, - ties: schema.regularSeasonStandings.ties, - winPct: schema.regularSeasonStandings.winPct, - gamesPlayed: schema.regularSeasonStandings.gamesPlayed, - gamesBack: schema.regularSeasonStandings.gamesBack, - conference: schema.regularSeasonStandings.conference, - division: schema.regularSeasonStandings.division, - conferenceRank: schema.regularSeasonStandings.conferenceRank, - divisionRank: schema.regularSeasonStandings.divisionRank, - leagueRank: schema.regularSeasonStandings.leagueRank, - streak: schema.regularSeasonStandings.streak, - lastTen: schema.regularSeasonStandings.lastTen, - homeRecord: schema.regularSeasonStandings.homeRecord, - awayRecord: schema.regularSeasonStandings.awayRecord, - externalTeamId: schema.regularSeasonStandings.externalTeamId, - syncedAt: schema.regularSeasonStandings.syncedAt, - updatedAt: schema.regularSeasonStandings.updatedAt, + wins: sql`excluded.wins`, + losses: sql`excluded.losses`, + otLosses: sql`excluded.ot_losses`, + ties: sql`excluded.ties`, + winPct: sql`excluded.win_pct`, + gamesPlayed: sql`excluded.games_played`, + gamesBack: sql`excluded.games_back`, + conference: sql`excluded.conference`, + division: sql`excluded.division`, + conferenceRank: sql`excluded.conference_rank`, + divisionRank: sql`excluded.division_rank`, + leagueRank: sql`excluded.league_rank`, + streak: sql`excluded.streak`, + lastTen: sql`excluded.last_ten`, + homeRecord: sql`excluded.home_record`, + awayRecord: sql`excluded.away_record`, + externalTeamId: sql`excluded.external_team_id`, + syncedAt: sql`excluded.synced_at`, + updatedAt: sql`excluded.updated_at`, }, }) .returning();