From 66145a9d78c179410b244dccc0fd444df00ce518 Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Fri, 1 May 2026 06:16:19 +0000 Subject: [PATCH] refactor(schema): rename per-window tables to season_* prefix Renames participants, participant_expected_values, participant_qualifying_totals, participant_results, participant_surface_elos to season_* prefixed names. Renames event_results.participant_id to season_participant_id. Phase 1a of canonical tournament layer migration. Co-Authored-By: Claude Opus 4.7 --- database/schema.ts | 180 ++++++++++++++++++++++----------------------- 1 file changed, 90 insertions(+), 90 deletions(-) diff --git a/database/schema.ts b/database/schema.ts index 4fbb104..6fa32f0 100644 --- a/database/schema.ts +++ b/database/schema.ts @@ -249,7 +249,7 @@ export const draftPicks = pgTable("draft_picks", { .references(() => teams.id, { onDelete: "cascade" }), participantId: uuid("participant_id") .notNull() - .references(() => participants.id, { onDelete: "cascade" }), + .references(() => seasonParticipants.id, { onDelete: "cascade" }), pickNumber: integer("pick_number").notNull(), round: integer("round").notNull(), pickInRound: integer("pick_in_round").notNull(), @@ -272,7 +272,7 @@ export const draftQueue = pgTable("draft_queue", { .references(() => teams.id, { onDelete: "cascade" }), participantId: uuid("participant_id") .notNull() - .references(() => participants.id, { onDelete: "cascade" }), + .references(() => seasonParticipants.id, { onDelete: "cascade" }), queuePosition: integer("queue_position").notNull(), createdAt: timestamp("created_at").defaultNow().notNull(), updatedAt: timestamp("updated_at").defaultNow().notNull(), @@ -288,7 +288,7 @@ export const watchlist = pgTable("watchlist", { .references(() => teams.id, { onDelete: "cascade" }), participantId: uuid("participant_id") .notNull() - .references(() => participants.id, { onDelete: "cascade" }), + .references(() => seasonParticipants.id, { onDelete: "cascade" }), createdAt: timestamp("created_at").defaultNow().notNull(), }, (t) => ({ uniqueWatch: uniqueIndex("watchlist_season_team_participant_unique").on(t.seasonId, t.teamId, t.participantId), @@ -373,7 +373,7 @@ export const sportsSeasons = pgTable("sports_seasons", { updatedAt: timestamp("updated_at").defaultNow().notNull(), }); -export const participants = pgTable("participants", { +export const seasonParticipants = pgTable("season_participants", { id: uuid("id").primaryKey().defaultRandom(), sportsSeasonId: uuid("sports_season_id") .notNull() @@ -411,11 +411,11 @@ export const seasonSports = pgTable("season_sports", { createdAt: timestamp("created_at").defaultNow().notNull(), }); -export const participantResults = pgTable("participant_results", { +export const seasonParticipantResults = pgTable("season_participant_results", { id: uuid("id").primaryKey().defaultRandom(), participantId: uuid("participant_id") .notNull() - .references(() => participants.id, { onDelete: "cascade" }), + .references(() => seasonParticipants.id, { onDelete: "cascade" }), sportsSeasonId: uuid("sports_season_id") .notNull() .references(() => sportsSeasons.id, { onDelete: "cascade" }), @@ -460,9 +460,9 @@ export const eventResults = pgTable("event_results", { scoringEventId: uuid("scoring_event_id") .notNull() .references(() => scoringEvents.id, { onDelete: "cascade" }), - participantId: uuid("participant_id") + seasonParticipantId: uuid("season_participant_id") .notNull() - .references(() => participants.id, { onDelete: "cascade" }), + .references(() => seasonParticipants.id, { onDelete: "cascade" }), // Placement in this specific event placement: integer("placement"), // For qualifying events: QP awarded in this event @@ -483,10 +483,10 @@ export const playoffMatches = pgTable("playoff_matches", { .references(() => scoringEvents.id, { onDelete: "cascade" }), round: varchar("round", { length: 50 }).notNull(), // "Quarterfinals", "Semifinals", "Finals" matchNumber: integer("match_number").notNull(), // 1, 2, 3, 4 (for QF); 1, 2 (for SF); 1 (for F) - participant1Id: uuid("participant1_id").references(() => participants.id, { onDelete: "set null" }), - participant2Id: uuid("participant2_id").references(() => participants.id, { onDelete: "set null" }), - winnerId: uuid("winner_id").references(() => participants.id, { onDelete: "set null" }), - loserId: uuid("loser_id").references(() => participants.id, { onDelete: "set null" }), + participant1Id: uuid("participant1_id").references(() => seasonParticipants.id, { onDelete: "set null" }), + participant2Id: uuid("participant2_id").references(() => seasonParticipants.id, { onDelete: "set null" }), + winnerId: uuid("winner_id").references(() => seasonParticipants.id, { onDelete: "set null" }), + loserId: uuid("loser_id").references(() => seasonParticipants.id, { onDelete: "set null" }), isComplete: boolean("is_complete").notNull().default(false), // Optional detailed data participant1Score: decimal("participant1_score", { precision: 10, scale: 2 }), @@ -510,7 +510,7 @@ export const playoffMatchGames = pgTable("playoff_match_games", { status: playoffMatchGameStatusEnum("status").notNull().default("scheduled"), participant1Score: decimal("participant1_score", { precision: 10, scale: 2 }), participant2Score: decimal("participant2_score", { precision: 10, scale: 2 }), - winnerId: uuid("winner_id").references(() => participants.id, { onDelete: "set null" }), + winnerId: uuid("winner_id").references(() => seasonParticipants.id, { onDelete: "set null" }), notes: text("notes"), createdAt: timestamp("created_at").defaultNow().notNull(), updatedAt: timestamp("updated_at").defaultNow().notNull(), @@ -524,7 +524,7 @@ export const playoffMatchOdds = pgTable("playoff_match_odds", { .references(() => playoffMatches.id, { onDelete: "cascade" }), participantId: uuid("participant_id") .notNull() - .references(() => participants.id, { onDelete: "cascade" }), + .references(() => seasonParticipants.id, { onDelete: "cascade" }), moneylineOdds: integer("moneyline_odds"), // American format e.g. -110, +150 impliedProbability: decimal("implied_probability", { precision: 6, scale: 4 }), oddsSource: varchar("odds_source", { length: 100 }), @@ -534,11 +534,11 @@ export const playoffMatchOdds = pgTable("playoff_match_odds", { }); // Aggregated participant qualifying points (for qualifying_points sports) -export const participantQualifyingTotals = pgTable("participant_qualifying_totals", { +export const seasonParticipantQualifyingTotals = pgTable("season_participant_qualifying_totals", { id: uuid("id").primaryKey().defaultRandom(), participantId: uuid("participant_id") .notNull() - .references(() => participants.id, { onDelete: "cascade" }), + .references(() => seasonParticipants.id, { onDelete: "cascade" }), sportsSeasonId: uuid("sports_season_id") .notNull() .references(() => sportsSeasons.id, { onDelete: "cascade" }), @@ -639,11 +639,11 @@ export const teamStandingsSnapshots = pgTable("team_standings_snapshots", { })); // Expected value tracking (sports-season-specific) -export const participantExpectedValues = pgTable("participant_expected_values", { +export const seasonParticipantExpectedValues = pgTable("season_participant_expected_values", { id: uuid("id").primaryKey().defaultRandom(), participantId: uuid("participant_id") .notNull() - .references(() => participants.id, { onDelete: "cascade" }), + .references(() => seasonParticipants.id, { onDelete: "cascade" }), sportsSeasonId: uuid("sports_season_id") .notNull() .references(() => sportsSeasons.id, { onDelete: "cascade" }), @@ -688,7 +688,7 @@ export const tournamentGroupMembers = pgTable("tournament_group_members", { .references(() => tournamentGroups.id, { onDelete: "cascade" }), participantId: uuid("participant_id") .notNull() - .references(() => participants.id, { onDelete: "cascade" }), + .references(() => seasonParticipants.id, { onDelete: "cascade" }), eliminated: boolean("eliminated").notNull().default(false), createdAt: timestamp("created_at").defaultNow().notNull(), updatedAt: timestamp("updated_at").defaultNow().notNull(), @@ -701,10 +701,10 @@ export const groupStageMatches = pgTable("group_stage_matches", { .references(() => tournamentGroups.id, { onDelete: "cascade" }), participant1Id: uuid("participant1_id") .notNull() - .references(() => participants.id), + .references(() => seasonParticipants.id), participant2Id: uuid("participant2_id") .notNull() - .references(() => participants.id), + .references(() => seasonParticipants.id), participant1Score: integer("participant1_score"), participant2Score: integer("participant2_score"), isComplete: boolean("is_complete").notNull().default(false), @@ -723,7 +723,7 @@ export const participantSeasonResults = pgTable("participant_season_results", { id: uuid("id").primaryKey().defaultRandom(), participantId: uuid("participant_id") .notNull() - .references(() => participants.id, { onDelete: "cascade" }), + .references(() => seasonParticipants.id, { onDelete: "cascade" }), sportsSeasonId: uuid("sports_season_id") .notNull() .references(() => sportsSeasons.id, { onDelete: "cascade" }), @@ -737,7 +737,7 @@ export const participantEvSnapshots = pgTable("participant_ev_snapshots", { id: uuid("id").primaryKey().defaultRandom(), participantId: uuid("participant_id") .notNull() - .references(() => participants.id, { onDelete: "cascade" }), + .references(() => seasonParticipants.id, { onDelete: "cascade" }), sportsSeasonId: uuid("sports_season_id") .notNull() .references(() => sportsSeasons.id, { onDelete: "cascade" }), @@ -790,20 +790,20 @@ export const sportsSeasonsRelations = relations(sportsSeasons, ({ one, many }) = fields: [sportsSeasons.sportId], references: [sports.id], }), - participants: many(participants), + participants: many(seasonParticipants), seasonTemplateSports: many(seasonTemplateSports), seasonSports: many(seasonSports), - participantResults: many(participantResults), + participantResults: many(seasonParticipantResults), regularSeasonStandings: many(regularSeasonStandings), pendingStandingsMappings: many(pendingStandingsMappings), })); -export const participantsRelations = relations(participants, ({ one, many }) => ({ +export const seasonParticipantsRelations = relations(seasonParticipants, ({ one, many }) => ({ sportsSeason: one(sportsSeasons, { - fields: [participants.sportsSeasonId], + fields: [seasonParticipants.sportsSeasonId], references: [sportsSeasons.id], }), - results: many(participantResults), + results: many(seasonParticipantResults), regularSeasonStandings: many(regularSeasonStandings), })); @@ -847,13 +847,13 @@ export const seasonSportsRelations = relations(seasonSports, ({ one }) => ({ }), })); -export const participantResultsRelations = relations(participantResults, ({ one }) => ({ - participant: one(participants, { - fields: [participantResults.participantId], - references: [participants.id], +export const seasonParticipantResultsRelations = relations(seasonParticipantResults, ({ one }) => ({ + participant: one(seasonParticipants, { + fields: [seasonParticipantResults.participantId], + references: [seasonParticipants.id], }), sportsSeason: one(sportsSeasons, { - fields: [participantResults.sportsSeasonId], + fields: [seasonParticipantResults.sportsSeasonId], references: [sportsSeasons.id], }), })); @@ -889,9 +889,9 @@ export const draftPicksRelations = relations(draftPicks, ({ one }) => ({ fields: [draftPicks.teamId], references: [teams.id], }), - participant: one(participants, { + participant: one(seasonParticipants, { fields: [draftPicks.participantId], - references: [participants.id], + references: [seasonParticipants.id], }), })); @@ -904,9 +904,9 @@ export const draftQueueRelations = relations(draftQueue, ({ one }) => ({ fields: [draftQueue.teamId], references: [teams.id], }), - participant: one(participants, { + participant: one(seasonParticipants, { fields: [draftQueue.participantId], - references: [participants.id], + references: [seasonParticipants.id], }), })); @@ -919,9 +919,9 @@ export const watchlistRelations = relations(watchlist, ({ one }) => ({ fields: [watchlist.teamId], references: [teams.id], }), - participant: one(participants, { + participant: one(seasonParticipants, { fields: [watchlist.participantId], - references: [participants.id], + references: [seasonParticipants.id], }), })); @@ -954,9 +954,9 @@ export const eventResultsRelations = relations(eventResults, ({ one }) => ({ fields: [eventResults.scoringEventId], references: [scoringEvents.id], }), - participant: one(participants, { - fields: [eventResults.participantId], - references: [participants.id], + seasonParticipant: one(seasonParticipants, { + fields: [eventResults.seasonParticipantId], + references: [seasonParticipants.id], }), })); @@ -965,21 +965,21 @@ export const playoffMatchesRelations = relations(playoffMatches, ({ one, many }) fields: [playoffMatches.scoringEventId], references: [scoringEvents.id], }), - participant1: one(participants, { + participant1: one(seasonParticipants, { fields: [playoffMatches.participant1Id], - references: [participants.id], + references: [seasonParticipants.id], }), - participant2: one(participants, { + participant2: one(seasonParticipants, { fields: [playoffMatches.participant2Id], - references: [participants.id], + references: [seasonParticipants.id], }), - winner: one(participants, { + winner: one(seasonParticipants, { fields: [playoffMatches.winnerId], - references: [participants.id], + references: [seasonParticipants.id], }), - loser: one(participants, { + loser: one(seasonParticipants, { fields: [playoffMatches.loserId], - references: [participants.id], + references: [seasonParticipants.id], }), games: many(playoffMatchGames), odds: many(playoffMatchOdds), @@ -990,9 +990,9 @@ export const playoffMatchGamesRelations = relations(playoffMatchGames, ({ one }) fields: [playoffMatchGames.playoffMatchId], references: [playoffMatches.id], }), - winner: one(participants, { + winner: one(seasonParticipants, { fields: [playoffMatchGames.winnerId], - references: [participants.id], + references: [seasonParticipants.id], }), })); @@ -1001,19 +1001,19 @@ export const playoffMatchOddsRelations = relations(playoffMatchOdds, ({ one }) = fields: [playoffMatchOdds.playoffMatchId], references: [playoffMatches.id], }), - participant: one(participants, { + participant: one(seasonParticipants, { fields: [playoffMatchOdds.participantId], - references: [participants.id], + references: [seasonParticipants.id], }), })); -export const participantQualifyingTotalsRelations = relations(participantQualifyingTotals, ({ one }) => ({ - participant: one(participants, { - fields: [participantQualifyingTotals.participantId], - references: [participants.id], +export const seasonParticipantQualifyingTotalsRelations = relations(seasonParticipantQualifyingTotals, ({ one }) => ({ + participant: one(seasonParticipants, { + fields: [seasonParticipantQualifyingTotals.participantId], + references: [seasonParticipants.id], }), sportsSeason: one(sportsSeasons, { - fields: [participantQualifyingTotals.sportsSeasonId], + fields: [seasonParticipantQualifyingTotals.sportsSeasonId], references: [sportsSeasons.id], }), })); @@ -1058,21 +1058,21 @@ export const teamStandingsSnapshotsRelations = relations(teamStandingsSnapshots, }), })); -export const participantExpectedValuesRelations = relations(participantExpectedValues, ({ one }) => ({ - participant: one(participants, { - fields: [participantExpectedValues.participantId], - references: [participants.id], +export const seasonParticipantExpectedValuesRelations = relations(seasonParticipantExpectedValues, ({ one }) => ({ + participant: one(seasonParticipants, { + fields: [seasonParticipantExpectedValues.participantId], + references: [seasonParticipants.id], }), sportsSeason: one(sportsSeasons, { - fields: [participantExpectedValues.sportsSeasonId], + fields: [seasonParticipantExpectedValues.sportsSeasonId], references: [sportsSeasons.id], }), })); export const participantSeasonResultsRelations = relations(participantSeasonResults, ({ one }) => ({ - participant: one(participants, { + participant: one(seasonParticipants, { fields: [participantSeasonResults.participantId], - references: [participants.id], + references: [seasonParticipants.id], }), sportsSeason: one(sportsSeasons, { fields: [participantSeasonResults.sportsSeasonId], @@ -1095,9 +1095,9 @@ export const tournamentGroupMembersRelations = relations(tournamentGroupMembers, fields: [tournamentGroupMembers.tournamentGroupId], references: [tournamentGroups.id], }), - participant: one(participants, { + participant: one(seasonParticipants, { fields: [tournamentGroupMembers.participantId], - references: [participants.id], + references: [seasonParticipants.id], }), })); @@ -1106,22 +1106,22 @@ export const groupStageMatchesRelations = relations(groupStageMatches, ({ one }) fields: [groupStageMatches.tournamentGroupId], references: [tournamentGroups.id], }), - participant1: one(participants, { + participant1: one(seasonParticipants, { fields: [groupStageMatches.participant1Id], - references: [participants.id], + references: [seasonParticipants.id], relationName: "groupMatchParticipant1", }), - participant2: one(participants, { + participant2: one(seasonParticipants, { fields: [groupStageMatches.participant2Id], - references: [participants.id], + references: [seasonParticipants.id], relationName: "groupMatchParticipant2", }), })); export const participantEvSnapshotsRelations = relations(participantEvSnapshots, ({ one }) => ({ - participant: one(participants, { + participant: one(seasonParticipants, { fields: [participantEvSnapshots.participantId], - references: [participants.id], + references: [seasonParticipants.id], }), sportsSeason: one(sportsSeasons, { fields: [participantEvSnapshots.sportsSeasonId], @@ -1146,7 +1146,7 @@ export const regularSeasonStandings = pgTable("regular_season_standings", { id: uuid("id").primaryKey().defaultRandom(), participantId: uuid("participant_id") .notNull() - .references(() => participants.id, { onDelete: "cascade" }), + .references(() => seasonParticipants.id, { onDelete: "cascade" }), sportsSeasonId: uuid("sports_season_id") .notNull() .references(() => sportsSeasons.id, { onDelete: "cascade" }), @@ -1177,9 +1177,9 @@ export const regularSeasonStandings = pgTable("regular_season_standings", { })); export const regularSeasonStandingsRelations = relations(regularSeasonStandings, ({ one }) => ({ - participant: one(participants, { + participant: one(seasonParticipants, { fields: [regularSeasonStandings.participantId], - references: [participants.id], + references: [seasonParticipants.id], }), sportsSeason: one(sportsSeasons, { fields: [regularSeasonStandings.sportsSeasonId], @@ -1216,11 +1216,11 @@ export const pendingStandingsMappingsRelations = relations(pendingStandingsMappi // Stores surface-specific Elo ratings for tennis (and future surface-based sports). // One row per (participantId, sportsSeasonId); nullable per surface. -export const participantSurfaceElos = pgTable("participant_surface_elos", { +export const seasonParticipantSurfaceElos = pgTable("season_participant_surface_elos", { id: uuid("id").primaryKey().defaultRandom(), participantId: uuid("participant_id") .notNull() - .references(() => participants.id, { onDelete: "cascade" }), + .references(() => seasonParticipants.id, { onDelete: "cascade" }), sportsSeasonId: uuid("sports_season_id") .notNull() .references(() => sportsSeasons.id, { onDelete: "cascade" }), @@ -1234,13 +1234,13 @@ export const participantSurfaceElos = pgTable("participant_surface_elos", { .on(t.participantId, t.sportsSeasonId), })); -export const participantSurfaceElosRelations = relations(participantSurfaceElos, ({ one }) => ({ - participant: one(participants, { - fields: [participantSurfaceElos.participantId], - references: [participants.id], +export const seasonParticipantSurfaceElosRelations = relations(seasonParticipantSurfaceElos, ({ one }) => ({ + participant: one(seasonParticipants, { + fields: [seasonParticipantSurfaceElos.participantId], + references: [seasonParticipants.id], }), sportsSeason: one(sportsSeasons, { - fields: [participantSurfaceElos.sportsSeasonId], + fields: [seasonParticipantSurfaceElos.sportsSeasonId], references: [sportsSeasons.id], }), })); @@ -1255,7 +1255,7 @@ export const participantGolfSkills = pgTable("participant_golf_skills", { id: uuid("id").primaryKey().defaultRandom(), participantId: uuid("participant_id") .notNull() - .references(() => participants.id, { onDelete: "cascade" }), + .references(() => seasonParticipants.id, { onDelete: "cascade" }), sportsSeasonId: uuid("sports_season_id") .notNull() .references(() => sportsSeasons.id, { onDelete: "cascade" }), @@ -1275,9 +1275,9 @@ export const participantGolfSkills = pgTable("participant_golf_skills", { })); export const participantGolfSkillsRelations = relations(participantGolfSkills, ({ one }) => ({ - participant: one(participants, { + participant: one(seasonParticipants, { fields: [participantGolfSkills.participantId], - references: [participants.id], + references: [seasonParticipants.id], }), sportsSeason: one(sportsSeasons, { fields: [participantGolfSkills.sportsSeasonId], @@ -1302,7 +1302,7 @@ export const cs2MajorStageResults = pgTable("cs2_major_stage_results", { .references(() => scoringEvents.id, { onDelete: "cascade" }), participantId: uuid("participant_id") .notNull() - .references(() => participants.id, { onDelete: "cascade" }), + .references(() => seasonParticipants.id, { onDelete: "cascade" }), stageEntry: integer("stage_entry").notNull(), stageEliminated: integer("stage_eliminated"), stageEliminatedWins: integer("stage_eliminated_wins"), @@ -1319,9 +1319,9 @@ export const cs2MajorStageResultsRelations = relations(cs2MajorStageResults, ({ fields: [cs2MajorStageResults.scoringEventId], references: [scoringEvents.id], }), - participant: one(participants, { + participant: one(seasonParticipants, { fields: [cs2MajorStageResults.participantId], - references: [participants.id], + references: [seasonParticipants.id], }), }));