schema: add unique (scoring_event_id, season_participant_id) on event_results

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 <noreply@anthropic.com>
This commit is contained in:
Chris Parsons 2026-05-01 21:44:05 +00:00
parent faa0c0aa72
commit 699fb1f982
No known key found for this signature in database

View file

@ -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", {