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 <noreply@anthropic.com>
This commit is contained in:
parent
784f6859e4
commit
5b2407bec1
1 changed files with 20 additions and 20 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue