diff --git a/app/services/probability-updater.ts b/app/services/probability-updater.ts index 1ec048d..b6fd7cc 100644 --- a/app/services/probability-updater.ts +++ b/app/services/probability-updater.ts @@ -252,8 +252,8 @@ export async function previewProbabilityUpdate( const results = await findParticipantResultsBySportsSeasonId(sportsSeasonId); // Get all existing EVs with participant names - const existingEVs = await db.query.participantExpectedValues.findMany({ - where: eq(schema.participantExpectedValues.sportsSeasonId, sportsSeasonId), + const existingEVs = await db.query.seasonParticipantExpectedValues.findMany({ + where: eq(schema.seasonParticipantExpectedValues.sportsSeasonId, sportsSeasonId), with: { participant: true, }, diff --git a/app/services/simulations/afl-simulator.ts b/app/services/simulations/afl-simulator.ts index 5616844..9168c17 100644 --- a/app/services/simulations/afl-simulator.ts +++ b/app/services/simulations/afl-simulator.ts @@ -198,16 +198,16 @@ export class AFLSimulator implements Simulator { // 1. Load participants, DB Elo, and standings in parallel. const [participantRows, evRows, standings] = await Promise.all([ db - .select({ id: schema.participants.id, name: schema.participants.name }) - .from(schema.participants) - .where(eq(schema.participants.sportsSeasonId, sportsSeasonId)), + .select({ id: schema.seasonParticipants.id, name: schema.seasonParticipants.name }) + .from(schema.seasonParticipants) + .where(eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonId)), db .select({ - participantId: schema.participantExpectedValues.participantId, - sourceElo: schema.participantExpectedValues.sourceElo, + participantId: schema.seasonParticipantExpectedValues.participantId, + sourceElo: schema.seasonParticipantExpectedValues.sourceElo, }) - .from(schema.participantExpectedValues) - .where(eq(schema.participantExpectedValues.sportsSeasonId, sportsSeasonId)), + .from(schema.seasonParticipantExpectedValues) + .where(eq(schema.seasonParticipantExpectedValues.sportsSeasonId, sportsSeasonId)), getRegularSeasonStandings(sportsSeasonId), ]); diff --git a/app/services/simulations/auto-racing-simulator.ts b/app/services/simulations/auto-racing-simulator.ts index ee73f14..64072ee 100644 --- a/app/services/simulations/auto-racing-simulator.ts +++ b/app/services/simulations/auto-racing-simulator.ts @@ -103,8 +103,8 @@ export class AutoRacingSimulator implements Simulator { const db = database(); // 1. Load all participants for this sports season - const participants = await db.query.participants.findMany({ - where: eq(schema.participants.sportsSeasonId, sportsSeasonId), + const participants = await db.query.seasonParticipants.findMany({ + where: eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonId), }); if (participants.length === 0) { diff --git a/app/services/simulations/bracket-simulator.ts b/app/services/simulations/bracket-simulator.ts index 80cd30b..12a17c4 100644 --- a/app/services/simulations/bracket-simulator.ts +++ b/app/services/simulations/bracket-simulator.ts @@ -11,7 +11,7 @@ */ import { database } from "~/database/context"; -import { participantExpectedValues } from "~/database/schema"; +import { seasonParticipantExpectedValues } from "~/database/schema"; import { eq } from "drizzle-orm"; import { simulateBracket } from "~/services/bracket-simulator"; import { convertFuturesToElo } from "~/services/probability-engine"; @@ -24,12 +24,12 @@ export class BracketSimulator implements Simulator { // Load all participants with their current EVs (which hold probability distributions) const evRows = await db .select({ - participantId: participantExpectedValues.participantId, - probFirst: participantExpectedValues.probFirst, - sourceOdds: participantExpectedValues.sourceOdds, + participantId: seasonParticipantExpectedValues.participantId, + probFirst: seasonParticipantExpectedValues.probFirst, + sourceOdds: seasonParticipantExpectedValues.sourceOdds, }) - .from(participantExpectedValues) - .where(eq(participantExpectedValues.sportsSeasonId, sportsSeasonId)); + .from(seasonParticipantExpectedValues) + .where(eq(seasonParticipantExpectedValues.sportsSeasonId, sportsSeasonId)); if (evRows.length === 0) { throw new Error( diff --git a/app/services/simulations/cs-major-simulator.ts b/app/services/simulations/cs-major-simulator.ts index 2213d61..030ddef 100644 --- a/app/services/simulations/cs-major-simulator.ts +++ b/app/services/simulations/cs-major-simulator.ts @@ -433,9 +433,9 @@ export class CSMajorSimulator implements Simulator { // 1. Load all participants for this sports season. const allParticipants = await db - .select({ id: schema.participants.id }) - .from(schema.participants) - .where(eq(schema.participants.sportsSeasonId, sportsSeasonId)); + .select({ id: schema.seasonParticipants.id }) + .from(schema.seasonParticipants) + .where(eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonId)); const participantIds = allParticipants.map((p) => p.id); @@ -446,12 +446,12 @@ export class CSMajorSimulator implements Simulator { // 2. Load Elo ratings and world rankings from participantExpectedValues. const evRows = await db .select({ - participantId: schema.participantExpectedValues.participantId, - sourceElo: schema.participantExpectedValues.sourceElo, - worldRanking: schema.participantExpectedValues.worldRanking, + participantId: schema.seasonParticipantExpectedValues.participantId, + sourceElo: schema.seasonParticipantExpectedValues.sourceElo, + worldRanking: schema.seasonParticipantExpectedValues.worldRanking, }) - .from(schema.participantExpectedValues) - .where(eq(schema.participantExpectedValues.sportsSeasonId, sportsSeasonId)); + .from(schema.seasonParticipantExpectedValues) + .where(eq(schema.seasonParticipantExpectedValues.sportsSeasonId, sportsSeasonId)); const eloMap = new Map(); for (const row of evRows) { @@ -508,7 +508,7 @@ export class CSMajorSimulator implements Simulator { if (completedEventIds.length > 0) { const actualResults = await db .select({ - participantId: schema.eventResults.participantId, + participantId: schema.eventResults.seasonParticipantId, qualifyingPointsAwarded: schema.eventResults.qualifyingPointsAwarded, }) .from(schema.eventResults) diff --git a/app/services/simulations/darts-simulator.ts b/app/services/simulations/darts-simulator.ts index 207d4e0..673b37c 100644 --- a/app/services/simulations/darts-simulator.ts +++ b/app/services/simulations/darts-simulator.ts @@ -220,12 +220,12 @@ export class DartsSimulator implements Simulator { // 3. Load Elo ratings and world rankings. const evRows = await db .select({ - participantId: schema.participantExpectedValues.participantId, - sourceElo: schema.participantExpectedValues.sourceElo, - worldRanking: schema.participantExpectedValues.worldRanking, + participantId: schema.seasonParticipantExpectedValues.participantId, + sourceElo: schema.seasonParticipantExpectedValues.sourceElo, + worldRanking: schema.seasonParticipantExpectedValues.worldRanking, }) - .from(schema.participantExpectedValues) - .where(eq(schema.participantExpectedValues.sportsSeasonId, sportsSeasonId)); + .from(schema.seasonParticipantExpectedValues) + .where(eq(schema.seasonParticipantExpectedValues.sportsSeasonId, sportsSeasonId)); const eloMap = new Map(); const rankingMap = new Map(); @@ -452,9 +452,9 @@ export class DartsSimulator implements Simulator { db: ReturnType ): Promise { const allParticipants = await db - .select({ id: schema.participants.id, name: schema.participants.name }) - .from(schema.participants) - .where(eq(schema.participants.sportsSeasonId, sportsSeasonId)); + .select({ id: schema.seasonParticipants.id, name: schema.seasonParticipants.name }) + .from(schema.seasonParticipants) + .where(eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonId)); if (allParticipants.length < 2) { throw new Error( diff --git a/app/services/simulations/golf-simulator.ts b/app/services/simulations/golf-simulator.ts index 3011de1..4687f3d 100644 --- a/app/services/simulations/golf-simulator.ts +++ b/app/services/simulations/golf-simulator.ts @@ -185,9 +185,9 @@ export class GolfSimulator implements Simulator { // Load participants, skills, QP config, and scoring events in parallel. const [allParticipants, skillsMap, qpConfigRows, events] = await Promise.all([ db - .select({ id: schema.participants.id }) - .from(schema.participants) - .where(eq(schema.participants.sportsSeasonId, sportsSeasonId)), + .select({ id: schema.seasonParticipants.id }) + .from(schema.seasonParticipants) + .where(eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonId)), getGolfSkillsMap(sportsSeasonId), getQPConfig(sportsSeasonId), db.query.scoringEvents.findMany({ @@ -226,7 +226,7 @@ export class GolfSimulator implements Simulator { if (completedEventIds.length > 0) { const actualResults = await db .select({ - participantId: schema.eventResults.participantId, + participantId: schema.eventResults.seasonParticipantId, qualifyingPointsAwarded: schema.eventResults.qualifyingPointsAwarded, }) .from(schema.eventResults) diff --git a/app/services/simulations/llws-simulator.ts b/app/services/simulations/llws-simulator.ts index 1ac4b01..b6dfcb3 100644 --- a/app/services/simulations/llws-simulator.ts +++ b/app/services/simulations/llws-simulator.ts @@ -264,9 +264,9 @@ export class LLWSSimulator implements Simulator { // 1. Load all participants. const participants = await db - .select({ id: schema.participants.id, name: schema.participants.name, externalId: schema.participants.externalId }) - .from(schema.participants) - .where(eq(schema.participants.sportsSeasonId, sportsSeasonId)); + .select({ id: schema.seasonParticipants.id, name: schema.seasonParticipants.name, externalId: schema.seasonParticipants.externalId }) + .from(schema.seasonParticipants) + .where(eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonId)); if (participants.length !== US_TEAM_COUNT + INTL_TEAM_COUNT) { throw new Error( @@ -278,11 +278,11 @@ export class LLWSSimulator implements Simulator { // 2. Load championship futures odds. const evRows = await db .select({ - participantId: schema.participantExpectedValues.participantId, - sourceOdds: schema.participantExpectedValues.sourceOdds, + participantId: schema.seasonParticipantExpectedValues.participantId, + sourceOdds: schema.seasonParticipantExpectedValues.sourceOdds, }) - .from(schema.participantExpectedValues) - .where(eq(schema.participantExpectedValues.sportsSeasonId, sportsSeasonId)); + .from(schema.seasonParticipantExpectedValues) + .where(eq(schema.seasonParticipantExpectedValues.sportsSeasonId, sportsSeasonId)); const rawOddsMap = new Map(); for (const row of evRows) { diff --git a/app/services/simulations/mlb-simulator.ts b/app/services/simulations/mlb-simulator.ts index a4a45e7..f8f2234 100644 --- a/app/services/simulations/mlb-simulator.ts +++ b/app/services/simulations/mlb-simulator.ts @@ -409,9 +409,9 @@ export class MLBSimulator implements Simulator { // 1. Load all participants for this sports season. const participantRows = await db - .select({ id: schema.participants.id, name: schema.participants.name }) - .from(schema.participants) - .where(eq(schema.participants.sportsSeasonId, sportsSeasonId)); + .select({ id: schema.seasonParticipants.id, name: schema.seasonParticipants.name }) + .from(schema.seasonParticipants) + .where(eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonId)); if (participantRows.length === 0) { throw new Error( @@ -452,12 +452,12 @@ export class MLBSimulator implements Simulator { const evRows = await db .select({ - participantId: schema.participantExpectedValues.participantId, - sourceOdds: schema.participantExpectedValues.sourceOdds, - sourceElo: schema.participantExpectedValues.sourceElo, + participantId: schema.seasonParticipantExpectedValues.participantId, + sourceOdds: schema.seasonParticipantExpectedValues.sourceOdds, + sourceElo: schema.seasonParticipantExpectedValues.sourceElo, }) - .from(schema.participantExpectedValues) - .where(eq(schema.participantExpectedValues.sportsSeasonId, sportsSeasonId)); + .from(schema.seasonParticipantExpectedValues) + .where(eq(schema.seasonParticipantExpectedValues.sportsSeasonId, sportsSeasonId)); const participantIdSet = new Set(participantIds); const oddsRows = evRows.filter( diff --git a/app/services/simulations/nba-simulator.ts b/app/services/simulations/nba-simulator.ts index cb4dacd..59cbd72 100644 --- a/app/services/simulations/nba-simulator.ts +++ b/app/services/simulations/nba-simulator.ts @@ -312,16 +312,16 @@ export class NBASimulator implements Simulator { // Load participant names and sourceElo values in parallel. const [participantRows, evRows] = await Promise.all([ db - .select({ id: schema.participants.id, name: schema.participants.name }) - .from(schema.participants) - .where(eq(schema.participants.sportsSeasonId, sportsSeasonId)), + .select({ id: schema.seasonParticipants.id, name: schema.seasonParticipants.name }) + .from(schema.seasonParticipants) + .where(eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonId)), db .select({ - participantId: schema.participantExpectedValues.participantId, - sourceElo: schema.participantExpectedValues.sourceElo, + participantId: schema.seasonParticipantExpectedValues.participantId, + sourceElo: schema.seasonParticipantExpectedValues.sourceElo, }) - .from(schema.participantExpectedValues) - .where(eq(schema.participantExpectedValues.sportsSeasonId, sportsSeasonId)), + .from(schema.seasonParticipantExpectedValues) + .where(eq(schema.seasonParticipantExpectedValues.sportsSeasonId, sportsSeasonId)), ]); const nameById = new Map(participantRows.map((r) => [r.id, r.name])); @@ -472,17 +472,17 @@ export class NBASimulator implements Simulator { const [participantRows, standings, evRows] = await Promise.all([ db - .select({ id: schema.participants.id, name: schema.participants.name }) - .from(schema.participants) - .where(eq(schema.participants.sportsSeasonId, sportsSeasonId)), + .select({ id: schema.seasonParticipants.id, name: schema.seasonParticipants.name }) + .from(schema.seasonParticipants) + .where(eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonId)), getRegularSeasonStandings(sportsSeasonId), db .select({ - participantId: schema.participantExpectedValues.participantId, - sourceElo: schema.participantExpectedValues.sourceElo, + participantId: schema.seasonParticipantExpectedValues.participantId, + sourceElo: schema.seasonParticipantExpectedValues.sourceElo, }) - .from(schema.participantExpectedValues) - .where(eq(schema.participantExpectedValues.sportsSeasonId, sportsSeasonId)), + .from(schema.seasonParticipantExpectedValues) + .where(eq(schema.seasonParticipantExpectedValues.sportsSeasonId, sportsSeasonId)), ]); if (participantRows.length === 0) { diff --git a/app/services/simulations/ncaa-football-simulator.ts b/app/services/simulations/ncaa-football-simulator.ts index d41fe9f..4ba53db 100644 --- a/app/services/simulations/ncaa-football-simulator.ts +++ b/app/services/simulations/ncaa-football-simulator.ts @@ -214,9 +214,9 @@ export class NCAAFootballSimulator implements Simulator { // 1. Load all participants for this sports season. const participants = await db - .select({ id: schema.participants.id }) - .from(schema.participants) - .where(eq(schema.participants.sportsSeasonId, sportsSeasonId)); + .select({ id: schema.seasonParticipants.id }) + .from(schema.seasonParticipants) + .where(eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonId)); if (participants.length < BRACKET_SIZE) { throw new Error( @@ -228,12 +228,12 @@ export class NCAAFootballSimulator implements Simulator { // 2. Load Elo/FPI ratings and optional futures odds in a single query. const evRows = await db .select({ - participantId: schema.participantExpectedValues.participantId, - sourceElo: schema.participantExpectedValues.sourceElo, - sourceOdds: schema.participantExpectedValues.sourceOdds, + participantId: schema.seasonParticipantExpectedValues.participantId, + sourceElo: schema.seasonParticipantExpectedValues.sourceElo, + sourceOdds: schema.seasonParticipantExpectedValues.sourceOdds, }) - .from(schema.participantExpectedValues) - .where(eq(schema.participantExpectedValues.sportsSeasonId, sportsSeasonId)); + .from(schema.seasonParticipantExpectedValues) + .where(eq(schema.seasonParticipantExpectedValues.sportsSeasonId, sportsSeasonId)); // Build Elo and raw odds maps in a single pass. const eloFromDb = new Map(); diff --git a/app/services/simulations/ncaam-simulator.ts b/app/services/simulations/ncaam-simulator.ts index 65a13ac..c721129 100644 --- a/app/services/simulations/ncaam-simulator.ts +++ b/app/services/simulations/ncaam-simulator.ts @@ -494,9 +494,9 @@ export class NCAAMSimulator implements Simulator { // 6. Load participant names from DB; build net rating lookup by ID. const participantRows = await db - .select({ id: schema.participants.id, name: schema.participants.name }) - .from(schema.participants) - .where(inArray(schema.participants.id, participantIds)); + .select({ id: schema.seasonParticipants.id, name: schema.seasonParticipants.name }) + .from(schema.seasonParticipants) + .where(inArray(schema.seasonParticipants.id, participantIds)); if (participantRows.length < participantIds.length) { const foundIds = new Set(participantRows.map((r) => r.id)); diff --git a/app/services/simulations/ncaaw-simulator.ts b/app/services/simulations/ncaaw-simulator.ts index 0d9e0a6..5e2c20e 100644 --- a/app/services/simulations/ncaaw-simulator.ts +++ b/app/services/simulations/ncaaw-simulator.ts @@ -457,9 +457,9 @@ export class NCAAWSimulator implements Simulator { // 6. Load participant names from DB; build Barthag lookup by ID. const participantRows = await db - .select({ id: schema.participants.id, name: schema.participants.name }) - .from(schema.participants) - .where(inArray(schema.participants.id, participantIds)); + .select({ id: schema.seasonParticipants.id, name: schema.seasonParticipants.name }) + .from(schema.seasonParticipants) + .where(inArray(schema.seasonParticipants.id, participantIds)); if (participantRows.length < participantIds.length) { const foundIds = new Set(participantRows.map((r) => r.id)); diff --git a/app/services/simulations/nfl-simulator.ts b/app/services/simulations/nfl-simulator.ts index 9b7e26d..e23d4af 100644 --- a/app/services/simulations/nfl-simulator.ts +++ b/app/services/simulations/nfl-simulator.ts @@ -296,8 +296,8 @@ export class NFLSimulator implements Simulator { const db = database(); // Load participants - const participants = await db.query.participants.findMany({ - where: eq(schema.participants.sportsSeasonId, sportsSeasonId), + const participants = await db.query.seasonParticipants.findMany({ + where: eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonId), }); if (participants.length === 0) { @@ -307,12 +307,12 @@ export class NFLSimulator implements Simulator { // Load EV rows (sourceElo + sourceOdds) const evRows = await db .select({ - participantId: schema.participantExpectedValues.participantId, - sourceElo: schema.participantExpectedValues.sourceElo, - sourceOdds: schema.participantExpectedValues.sourceOdds, + participantId: schema.seasonParticipantExpectedValues.participantId, + sourceElo: schema.seasonParticipantExpectedValues.sourceElo, + sourceOdds: schema.seasonParticipantExpectedValues.sourceOdds, }) - .from(schema.participantExpectedValues) - .where(eq(schema.participantExpectedValues.sportsSeasonId, sportsSeasonId)); + .from(schema.seasonParticipantExpectedValues) + .where(eq(schema.seasonParticipantExpectedValues.sportsSeasonId, sportsSeasonId)); // Build Elo map: prefer sourceElo, fall back to converting sourceOdds const eloMap = new Map(); diff --git a/app/services/simulations/nhl-simulator.ts b/app/services/simulations/nhl-simulator.ts index 5891634..8e24c30 100644 --- a/app/services/simulations/nhl-simulator.ts +++ b/app/services/simulations/nhl-simulator.ts @@ -278,18 +278,18 @@ export class NHLSimulator implements Simulator { // 1. Load participants, standings, and sourceElo values in parallel. const [participantRows, standings, evRows] = await Promise.all([ db - .select({ id: schema.participants.id, name: schema.participants.name }) - .from(schema.participants) - .where(eq(schema.participants.sportsSeasonId, sportsSeasonId)), + .select({ id: schema.seasonParticipants.id, name: schema.seasonParticipants.name }) + .from(schema.seasonParticipants) + .where(eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonId)), getRegularSeasonStandings(sportsSeasonId), db .select({ - participantId: schema.participantExpectedValues.participantId, - sourceElo: schema.participantExpectedValues.sourceElo, - sourceOdds: schema.participantExpectedValues.sourceOdds, + participantId: schema.seasonParticipantExpectedValues.participantId, + sourceElo: schema.seasonParticipantExpectedValues.sourceElo, + sourceOdds: schema.seasonParticipantExpectedValues.sourceOdds, }) - .from(schema.participantExpectedValues) - .where(eq(schema.participantExpectedValues.sportsSeasonId, sportsSeasonId)), + .from(schema.seasonParticipantExpectedValues) + .where(eq(schema.seasonParticipantExpectedValues.sportsSeasonId, sportsSeasonId)), ]); if (participantRows.length === 0) { @@ -620,17 +620,17 @@ export class NHLSimulator implements Simulator { // Load all participants and EV data in parallel. const [participantRows, evRows] = await Promise.all([ db - .select({ id: schema.participants.id, name: schema.participants.name }) - .from(schema.participants) - .where(eq(schema.participants.sportsSeasonId, sportsSeasonId)), + .select({ id: schema.seasonParticipants.id, name: schema.seasonParticipants.name }) + .from(schema.seasonParticipants) + .where(eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonId)), db .select({ - participantId: schema.participantExpectedValues.participantId, - sourceOdds: schema.participantExpectedValues.sourceOdds, - sourceElo: schema.participantExpectedValues.sourceElo, + participantId: schema.seasonParticipantExpectedValues.participantId, + sourceOdds: schema.seasonParticipantExpectedValues.sourceOdds, + sourceElo: schema.seasonParticipantExpectedValues.sourceElo, }) - .from(schema.participantExpectedValues) - .where(eq(schema.participantExpectedValues.sportsSeasonId, sportsSeasonId)), + .from(schema.seasonParticipantExpectedValues) + .where(eq(schema.seasonParticipantExpectedValues.sportsSeasonId, sportsSeasonId)), ]); const allParticipantIds = participantRows.map((r) => r.id); diff --git a/app/services/simulations/snooker-simulator.ts b/app/services/simulations/snooker-simulator.ts index a9e8a5c..2b4db9a 100644 --- a/app/services/simulations/snooker-simulator.ts +++ b/app/services/simulations/snooker-simulator.ts @@ -251,11 +251,11 @@ export class SnookerSimulator implements Simulator { // 3. Load Elo ratings from participantExpectedValues. const evRows = await db .select({ - participantId: schema.participantExpectedValues.participantId, - sourceElo: schema.participantExpectedValues.sourceElo, + participantId: schema.seasonParticipantExpectedValues.participantId, + sourceElo: schema.seasonParticipantExpectedValues.sourceElo, }) - .from(schema.participantExpectedValues) - .where(eq(schema.participantExpectedValues.sportsSeasonId, sportsSeasonId)); + .from(schema.seasonParticipantExpectedValues) + .where(eq(schema.seasonParticipantExpectedValues.sportsSeasonId, sportsSeasonId)); // Build Elo map; fall back to 1500 for any participant with no stored rating. const eloMap = new Map(); @@ -453,9 +453,9 @@ export class SnookerSimulator implements Simulator { db: ReturnType ): Promise { const allParticipants = await db - .select({ id: schema.participants.id, name: schema.participants.name }) - .from(schema.participants) - .where(eq(schema.participants.sportsSeasonId, sportsSeasonId)); + .select({ id: schema.seasonParticipants.id, name: schema.seasonParticipants.name }) + .from(schema.seasonParticipants) + .where(eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonId)); if (allParticipants.length < 17) { throw new Error( diff --git a/app/services/simulations/tennis-simulator.ts b/app/services/simulations/tennis-simulator.ts index 032cccb..e14591e 100644 --- a/app/services/simulations/tennis-simulator.ts +++ b/app/services/simulations/tennis-simulator.ts @@ -262,9 +262,9 @@ export class TennisSimulator implements Simulator { // 1. Load all participants for this sports season. const allParticipants = await db - .select({ id: schema.participants.id }) - .from(schema.participants) - .where(eq(schema.participants.sportsSeasonId, sportsSeasonId)); + .select({ id: schema.seasonParticipants.id }) + .from(schema.seasonParticipants) + .where(eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonId)); if (allParticipants.length < 128) { throw new Error( @@ -306,7 +306,7 @@ export class TennisSimulator implements Simulator { if (completedEventIds.length > 0) { const actualResults = await db .select({ - participantId: schema.eventResults.participantId, + participantId: schema.eventResults.seasonParticipantId, qualifyingPointsAwarded: schema.eventResults.qualifyingPointsAwarded, }) .from(schema.eventResults) diff --git a/app/services/simulations/ucl-simulator.ts b/app/services/simulations/ucl-simulator.ts index 18e6008..698431c 100644 --- a/app/services/simulations/ucl-simulator.ts +++ b/app/services/simulations/ucl-simulator.ts @@ -147,11 +147,11 @@ export class UCLSimulator implements Simulator { // 5. Load futures odds from participantExpectedValues. const evRows = await db .select({ - participantId: schema.participantExpectedValues.participantId, - sourceOdds: schema.participantExpectedValues.sourceOdds, + participantId: schema.seasonParticipantExpectedValues.participantId, + sourceOdds: schema.seasonParticipantExpectedValues.sourceOdds, }) - .from(schema.participantExpectedValues) - .where(eq(schema.participantExpectedValues.sportsSeasonId, sportsSeasonId)); + .from(schema.seasonParticipantExpectedValues) + .where(eq(schema.seasonParticipantExpectedValues.sportsSeasonId, sportsSeasonId)); const evMap = new Map(evRows.map((r) => [r.participantId, r])); diff --git a/app/services/simulations/wnba-simulator.ts b/app/services/simulations/wnba-simulator.ts index a820202..98b36a1 100644 --- a/app/services/simulations/wnba-simulator.ts +++ b/app/services/simulations/wnba-simulator.ts @@ -159,18 +159,18 @@ export class WNBASimulator implements Simulator { // 1. Load participants, standings, and futures odds in parallel. const [participantRows, standings, evRows] = await Promise.all([ db - .select({ id: schema.participants.id, name: schema.participants.name }) - .from(schema.participants) - .where(eq(schema.participants.sportsSeasonId, sportsSeasonId)), + .select({ id: schema.seasonParticipants.id, name: schema.seasonParticipants.name }) + .from(schema.seasonParticipants) + .where(eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonId)), getRegularSeasonStandings(sportsSeasonId), db .select({ - participantId: schema.participantExpectedValues.participantId, - sourceOdds: schema.participantExpectedValues.sourceOdds, - sourceElo: schema.participantExpectedValues.sourceElo, + participantId: schema.seasonParticipantExpectedValues.participantId, + sourceOdds: schema.seasonParticipantExpectedValues.sourceOdds, + sourceElo: schema.seasonParticipantExpectedValues.sourceElo, }) - .from(schema.participantExpectedValues) - .where(eq(schema.participantExpectedValues.sportsSeasonId, sportsSeasonId)), + .from(schema.seasonParticipantExpectedValues) + .where(eq(schema.seasonParticipantExpectedValues.sportsSeasonId, sportsSeasonId)), ]); if (participantRows.length === 0) { diff --git a/app/services/simulations/world-cup-simulator.ts b/app/services/simulations/world-cup-simulator.ts index 9a1a587..8e7b681 100644 --- a/app/services/simulations/world-cup-simulator.ts +++ b/app/services/simulations/world-cup-simulator.ts @@ -313,8 +313,8 @@ export class WorldCupSimulator implements Simulator { const db = database(); // 1. Load all participants for this season - const participantRows = await db.query.participants.findMany({ - where: eq(schema.participants.sportsSeasonId, sportsSeasonId), + const participantRows = await db.query.seasonParticipants.findMany({ + where: eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonId), }); if (participantRows.length === 0) { @@ -327,12 +327,12 @@ export class WorldCupSimulator implements Simulator { // 2. Load stored ratings (sourceElo from Elo page, sourceOdds from futures page) const evRows = await db .select({ - participantId: schema.participantExpectedValues.participantId, - sourceOdds: schema.participantExpectedValues.sourceOdds, - sourceElo: schema.participantExpectedValues.sourceElo, + participantId: schema.seasonParticipantExpectedValues.participantId, + sourceOdds: schema.seasonParticipantExpectedValues.sourceOdds, + sourceElo: schema.seasonParticipantExpectedValues.sourceElo, }) - .from(schema.participantExpectedValues) - .where(eq(schema.participantExpectedValues.sportsSeasonId, sportsSeasonId)); + .from(schema.seasonParticipantExpectedValues) + .where(eq(schema.seasonParticipantExpectedValues.sportsSeasonId, sportsSeasonId)); const evMap = new Map(evRows.map((r) => [r.participantId, r])); const participantSet = new Set(participantIds); diff --git a/app/services/standings-sync/index.ts b/app/services/standings-sync/index.ts index 1c272a4..fecb74f 100644 --- a/app/services/standings-sync/index.ts +++ b/app/services/standings-sync/index.ts @@ -1,7 +1,7 @@ import { database } from "~/database/context"; import { eq } from "drizzle-orm"; import * as schema from "~/database/schema"; -import { findParticipantsBySportsSeasonId, updateParticipant } from "~/models/participant"; +import { findParticipantsBySportsSeasonId, updateParticipant } from "~/models/season-participant"; import { upsertRegularSeasonStandings } from "~/models/regular-season-standings"; import { upsertPendingStandingsMappings } from "~/models/pending-standings-mappings"; import { findMatchingTeamName } from "~/lib/normalize-team-name"; diff --git a/app/utils/sports-data-sync.server.ts b/app/utils/sports-data-sync.server.ts index 1848913..d043e31 100644 --- a/app/utils/sports-data-sync.server.ts +++ b/app/utils/sports-data-sync.server.ts @@ -115,16 +115,16 @@ export async function exportSportsDataToJSON(): Promise { with: { sport: true }, orderBy: (s, { desc, asc }) => [desc(s.year), asc(s.name)], }), - db.query.participants.findMany({ + db.query.seasonParticipants.findMany({ with: { sportsSeason: { with: { sport: true } } }, orderBy: (p, { asc }) => [asc(p.name)], }), - db.query.participantExpectedValues.findMany({ + db.query.seasonParticipantExpectedValues.findMany({ with: { participant: { with: { sportsSeason: { with: { sport: true } } } }, }, }), - db.query.participantResults.findMany({ + db.query.seasonParticipantResults.findMany({ with: { participant: { with: { sportsSeason: { with: { sport: true } } } }, }, @@ -238,7 +238,7 @@ export async function importSportsDataFromJSON( // automatically removed when participants is deleted. await tx.delete(schema.seasonTemplateSports); await tx.delete(schema.seasonTemplates); - await tx.delete(schema.participants); // cascades to EVs + results + await tx.delete(schema.seasonParticipants); // cascades to EVs + results await tx.delete(schema.seasonSports); await tx.delete(schema.sportsSeasons); await tx.delete(schema.sports); @@ -358,28 +358,28 @@ export async function importSportsDataFromJSON( continue; } - const existing = await tx.query.participants.findFirst({ + const existing = await tx.query.seasonParticipants.findFirst({ where: and( - eq(schema.participants.sportsSeasonId, sportsSeasonId), - eq(schema.participants.name, participant.name) + eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonId), + eq(schema.seasonParticipants.name, participant.name) ), }); if (existing) { // Update all mutable fields (fixes: merge mode was silently skipping) await tx - .update(schema.participants) + .update(schema.seasonParticipants) .set({ shortName: participant.shortName, externalId: participant.externalId, expectedValue: String(participant.expectedValue ?? 0), }) - .where(eq(schema.participants.id, existing.id)); + .where(eq(schema.seasonParticipants.id, existing.id)); participantIdMap.set(`${sportsSeasonId}:${participant.name}`, existing.id); updated++; } else { const [created_] = await tx - .insert(schema.participants) + .insert(schema.seasonParticipants) .values({ sportsSeasonId, name: participant.name, @@ -413,10 +413,10 @@ export async function importSportsDataFromJSON( continue; } - const existingEV = await tx.query.participantExpectedValues.findFirst({ + const existingEV = await tx.query.seasonParticipantExpectedValues.findFirst({ where: and( - eq(schema.participantExpectedValues.participantId, participantId), - eq(schema.participantExpectedValues.sportsSeasonId, sportsSeasonId) + eq(schema.seasonParticipantExpectedValues.participantId, participantId), + eq(schema.seasonParticipantExpectedValues.sportsSeasonId, sportsSeasonId) ), }); @@ -446,25 +446,25 @@ export async function importSportsDataFromJSON( if (existingEV) { if (mode === "merge") { await tx - .update(schema.participantExpectedValues) + .update(schema.seasonParticipantExpectedValues) .set({ ...evValues, updatedAt: new Date() }) - .where(eq(schema.participantExpectedValues.id, existingEV.id)); + .where(eq(schema.seasonParticipantExpectedValues.id, existingEV.id)); await tx - .update(schema.participants) + .update(schema.seasonParticipants) .set({ expectedValue: ev.expectedValue }) - .where(eq(schema.participants.id, participantId)); + .where(eq(schema.seasonParticipants.id, participantId)); updated++; } } else { - await tx.insert(schema.participantExpectedValues).values({ + await tx.insert(schema.seasonParticipantExpectedValues).values({ participantId, sportsSeasonId, ...evValues, }); await tx - .update(schema.participants) + .update(schema.seasonParticipants) .set({ expectedValue: ev.expectedValue }) - .where(eq(schema.participants.id, participantId)); + .where(eq(schema.seasonParticipants.id, participantId)); created++; } } @@ -489,10 +489,10 @@ export async function importSportsDataFromJSON( continue; } - const existingResult = await tx.query.participantResults.findFirst({ + const existingResult = await tx.query.seasonParticipantResults.findFirst({ where: and( - eq(schema.participantResults.participantId, participantId), - eq(schema.participantResults.sportsSeasonId, sportsSeasonId) + eq(schema.seasonParticipantResults.participantId, participantId), + eq(schema.seasonParticipantResults.sportsSeasonId, sportsSeasonId) ), }); @@ -505,13 +505,13 @@ export async function importSportsDataFromJSON( if (existingResult) { if (mode === "merge") { await tx - .update(schema.participantResults) + .update(schema.seasonParticipantResults) .set({ ...resultValues, updatedAt: new Date() }) - .where(eq(schema.participantResults.id, existingResult.id)); + .where(eq(schema.seasonParticipantResults.id, existingResult.id)); updated++; } } else { - await tx.insert(schema.participantResults).values({ + await tx.insert(schema.seasonParticipantResults).values({ participantId, sportsSeasonId, ...resultValues, diff --git a/server/socket.ts b/server/socket.ts index 066e221..a8b32e1 100644 --- a/server/socket.ts +++ b/server/socket.ts @@ -232,18 +232,18 @@ export function initializeSocketIO(httpServer: HTTPServer): SocketIOServer { pickInRound: schema.draftPicks.pickInRound, timeUsed: schema.draftPicks.timeUsed, team: schema.teams, - participant: schema.participants, + participant: schema.seasonParticipants, sport: schema.sports, }) .from(schema.draftPicks) .innerJoin(schema.teams, eq(schema.draftPicks.teamId, schema.teams.id)) .innerJoin( - schema.participants, - eq(schema.draftPicks.participantId, schema.participants.id) + schema.seasonParticipants, + eq(schema.draftPicks.participantId, schema.seasonParticipants.id) ) .innerJoin( schema.sportsSeasons, - eq(schema.participants.sportsSeasonId, schema.sportsSeasons.id) + eq(schema.seasonParticipants.sportsSeasonId, schema.sportsSeasons.id) ) .innerJoin( schema.sports,