From 699fb1f9825e0df612ef5c068cf9f1764239e13c Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Fri, 1 May 2026 21:44:05 +0000 Subject: [PATCH] schema: add unique (scoring_event_id, season_participant_id) on event_results MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit syncTournamentResults uses check-then-write on event_results. The unique index defends against race conditions (unlikely today — admin is single-writer — but safe to enforce). WARNING: if existing prod data has duplicate (scoring_event_id, season_participant_id) pairs, the migration will fail. Verify with: SELECT scoring_event_id, season_participant_id, count(*) FROM event_results GROUP BY 1, 2 HAVING count(*) > 1; Co-Authored-By: Claude Opus 4.7 --- database/schema.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/database/schema.ts b/database/schema.ts index bff5ea5..37f009b 100644 --- a/database/schema.ts +++ b/database/schema.ts @@ -580,7 +580,12 @@ export const eventResults = pgTable("event_results", { rawScore: decimal("raw_score", { precision: 10, scale: 2 }), // strokes, points, time, etc. createdAt: timestamp("created_at").defaultNow().notNull(), updatedAt: timestamp("updated_at").defaultNow().notNull(), -}); +}, (t) => ({ + uniqueEventParticipant: uniqueIndex("event_results_event_participant_unique").on( + t.scoringEventId, + t.seasonParticipantId, + ), +})); // Playoff bracket matches (for display and tracking) export const playoffMatches = pgTable("playoff_matches", {