feat: Add comprehensive scoring system database schema

- Add scoringPattern and eventType enums for 4 scoring patterns
    (single_elimination_playoff, page_playoff, season_standings, qualifying_points)
  - Add 8 placement point fields to seasons table (1st-8th) with defaults
  - Add scoring pattern fields to sportsSeasons table (scoringPattern, totalMajors, etc.)
  - Create 10 new tables:
    - scoring_events: Individual games, tournaments, races
    - event_results: Participant results per event
    - playoff_matches: Bracket tracking for playoffs
    - participant_qualifying_totals: QP aggregation for golf/tennis
    - qualifying_point_config: Configurable QP values per sport
    - team_sport_scores: Aggregated scores per sport
    - team_standings: Current standings with tiebreakers
    - team_standings_snapshots: Daily snapshots for 7-day tracking
    - participant_expected_values: EV calculations per league
    - participant_season_results: F1 current points tracking
  - Add all necessary relations for new tables
  - Update test fixtures with new required scoring fields
This commit is contained in:
Chris Parsons 2025-10-28 23:39:34 -07:00
parent 1a1af87d3c
commit ad16f9d046
6 changed files with 3344 additions and 0 deletions

View file

@ -26,6 +26,14 @@ const createMockSeason = (overrides: {
draftStartedAt: null, draftStartedAt: null,
draftPaused: false, draftPaused: false,
inviteCode: 'ABC123', inviteCode: 'ABC123',
pointsFor1st: 100,
pointsFor2nd: 70,
pointsFor3rd: 50,
pointsFor4th: 40,
pointsFor5th: 25,
pointsFor6th: 25,
pointsFor7th: 15,
pointsFor8th: 15,
createdAt: new Date(), createdAt: new Date(),
updatedAt: new Date(), updatedAt: new Date(),
}); });

View file

@ -13,6 +13,14 @@ export const mockSeason = {
draftStartedAt: null, draftStartedAt: null,
draftPaused: false, draftPaused: false,
inviteCode: 'TEST123', inviteCode: 'TEST123',
pointsFor1st: 100,
pointsFor2nd: 70,
pointsFor3rd: 50,
pointsFor4th: 40,
pointsFor5th: 25,
pointsFor6th: 25,
pointsFor7th: 15,
pointsFor8th: 15,
createdAt: new Date('2025-01-01'), createdAt: new Date('2025-01-01'),
updatedAt: new Date('2025-01-01'), updatedAt: new Date('2025-01-01'),
}; };

View file

@ -39,6 +39,20 @@ export const scoringTypeEnum = pgEnum("scoring_type", [
"majors", "majors",
]); ]);
export const scoringPatternEnum = pgEnum("scoring_pattern", [
"single_elimination_playoff",
"page_playoff",
"season_standings",
"qualifying_points",
]);
export const eventTypeEnum = pgEnum("event_type", [
"playoff_game",
"major_tournament",
"race",
"final_standings",
]);
export const pickedByTypeEnum = pgEnum("picked_by_type", [ export const pickedByTypeEnum = pgEnum("picked_by_type", [
"owner", "owner",
"commissioner", "commissioner",
@ -88,6 +102,15 @@ export const seasons = pgTable("seasons", {
draftStartedAt: timestamp("draft_started_at"), draftStartedAt: timestamp("draft_started_at"),
draftPaused: boolean("draft_paused").notNull().default(false), draftPaused: boolean("draft_paused").notNull().default(false),
inviteCode: varchar("invite_code", { length: 20 }).notNull().unique(), inviteCode: varchar("invite_code", { length: 20 }).notNull().unique(),
// Scoring configuration (8 values for 1st through 8th)
pointsFor1st: integer("points_for_1st").notNull().default(100),
pointsFor2nd: integer("points_for_2nd").notNull().default(70),
pointsFor3rd: integer("points_for_3rd").notNull().default(50),
pointsFor4th: integer("points_for_4th").notNull().default(40),
pointsFor5th: integer("points_for_5th").notNull().default(25),
pointsFor6th: integer("points_for_6th").notNull().default(25),
pointsFor7th: integer("points_for_7th").notNull().default(15),
pointsFor8th: integer("points_for_8th").notNull().default(15),
createdAt: timestamp("created_at").defaultNow().notNull(), createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(), updatedAt: timestamp("updated_at").defaultNow().notNull(),
}); });
@ -211,6 +234,12 @@ export const sportsSeasons = pgTable("sports_seasons", {
endDate: date("end_date"), endDate: date("end_date"),
status: sportsSeasonStatusEnum("status").notNull().default("upcoming"), status: sportsSeasonStatusEnum("status").notNull().default("upcoming"),
scoringType: scoringTypeEnum("scoring_type").notNull(), scoringType: scoringTypeEnum("scoring_type").notNull(),
// New scoring pattern field (replaces/augments scoringType)
scoringPattern: scoringPatternEnum("scoring_pattern"),
// For qualifying points sports
totalMajors: integer("total_majors"),
majorsCompleted: integer("majors_completed").notNull().default(0),
qualifyingPointsFinalized: boolean("qualifying_points_finalized").notNull().default(false),
createdAt: timestamp("created_at").defaultNow().notNull(), createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(), updatedAt: timestamp("updated_at").defaultNow().notNull(),
}); });
@ -266,6 +295,199 @@ export const participantResults = pgTable("participant_results", {
updatedAt: timestamp("updated_at").defaultNow().notNull(), updatedAt: timestamp("updated_at").defaultNow().notNull(),
}); });
// Scoring System Tables
// Individual scoring events (games, tournaments, races)
export const scoringEvents = pgTable("scoring_events", {
id: uuid("id").primaryKey().defaultRandom(),
sportsSeasonId: uuid("sports_season_id")
.notNull()
.references(() => sportsSeasons.id, { onDelete: "cascade" }),
name: varchar("name", { length: 255 }).notNull(), // "2024 Masters", "Super Bowl LIX", etc.
eventDate: date("event_date"),
eventType: eventTypeEnum("event_type").notNull(),
// For playoff events
playoffRound: varchar("playoff_round", { length: 50 }), // "Quarterfinals", "Semifinals", "Finals"
// For qualifying events
isQualifyingEvent: boolean("is_qualifying_event").notNull().default(false),
isComplete: boolean("is_complete").notNull().default(false),
completedAt: timestamp("completed_at"),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
// Results for participants in specific events
export const eventResults = pgTable("event_results", {
id: uuid("id").primaryKey().defaultRandom(),
scoringEventId: uuid("scoring_event_id")
.notNull()
.references(() => scoringEvents.id, { onDelete: "cascade" }),
participantId: uuid("participant_id")
.notNull()
.references(() => participants.id, { onDelete: "cascade" }),
// Placement in this specific event
placement: integer("placement"),
// For qualifying events: QP awarded in this event
qualifyingPointsAwarded: decimal("qualifying_points_awarded", { precision: 10, scale: 2 }),
// For playoff events: eliminated or advanced
eliminated: boolean("eliminated"),
// Raw sport-specific data (optional)
rawScore: decimal("raw_score", { precision: 10, scale: 2 }), // strokes, points, time, etc.
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
// Playoff bracket matches (for display and tracking)
export const playoffMatches = pgTable("playoff_matches", {
id: uuid("id").primaryKey().defaultRandom(),
scoringEventId: uuid("scoring_event_id")
.notNull()
.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" }),
isComplete: boolean("is_complete").notNull().default(false),
// Optional detailed data
participant1Score: decimal("participant1_score", { precision: 10, scale: 2 }),
participant2Score: decimal("participant2_score", { precision: 10, scale: 2 }),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
// Aggregated participant qualifying points (for qualifying_points sports)
export const participantQualifyingTotals = pgTable("participant_qualifying_totals", {
id: uuid("id").primaryKey().defaultRandom(),
participantId: uuid("participant_id")
.notNull()
.references(() => participants.id, { onDelete: "cascade" }),
sportsSeasonId: uuid("sports_season_id")
.notNull()
.references(() => sportsSeasons.id, { onDelete: "cascade" }),
totalQualifyingPoints: decimal("total_qualifying_points", { precision: 10, scale: 2 }).notNull().default("0"),
eventsScored: integer("events_scored").notNull().default(0),
// After finalization
finalRanking: integer("final_ranking"), // 1-8 based on QP totals
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
// Configurable qualifying point values per sports season
export const qualifyingPointConfig = pgTable("qualifying_point_config", {
id: uuid("id").primaryKey().defaultRandom(),
sportsSeasonId: uuid("sports_season_id")
.notNull()
.references(() => sportsSeasons.id, { onDelete: "cascade" }),
placement: integer("placement").notNull(), // 1-16
points: decimal("points", { precision: 10, scale: 2 }).notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
// Team scores aggregated by sport season
export const teamSportScores = pgTable("team_sport_scores", {
id: uuid("id").primaryKey().defaultRandom(),
teamId: uuid("team_id")
.notNull()
.references(() => teams.id, { onDelete: "cascade" }),
sportsSeasonId: uuid("sports_season_id")
.notNull()
.references(() => sportsSeasons.id, { onDelete: "cascade" }),
totalPoints: decimal("total_points", { precision: 10, scale: 2 }).notNull().default("0"),
participantsCompleted: integer("participants_completed").notNull().default(0), // How many picks have finished
participantsTotal: integer("participants_total").notNull().default(0), // Total picks for this sport
calculatedAt: timestamp("calculated_at").defaultNow().notNull(),
});
// Overall team standings (snapshot-based for movement tracking)
export const teamStandings = pgTable("team_standings", {
id: uuid("id").primaryKey().defaultRandom(),
teamId: uuid("team_id")
.notNull()
.references(() => teams.id, { onDelete: "cascade" }),
seasonId: uuid("season_id")
.notNull()
.references(() => seasons.id, { onDelete: "cascade" }),
totalPoints: decimal("total_points", { precision: 10, scale: 2 }).notNull().default("0"),
currentRank: integer("current_rank").notNull(),
previousRank: integer("previous_rank"), // For movement indicators
// Tiebreaker data
firstPlaceCount: integer("first_place_count").notNull().default(0),
secondPlaceCount: integer("second_place_count").notNull().default(0),
thirdPlaceCount: integer("third_place_count").notNull().default(0),
fourthPlaceCount: integer("fourth_place_count").notNull().default(0),
fifthPlaceCount: integer("fifth_place_count").notNull().default(0),
sixthPlaceCount: integer("sixth_place_count").notNull().default(0),
seventhPlaceCount: integer("seventh_place_count").notNull().default(0),
eighthPlaceCount: integer("eighth_place_count").notNull().default(0),
participantsRemaining: integer("participants_remaining").notNull().default(0), // Not yet finished
calculatedAt: timestamp("calculated_at").defaultNow().notNull(),
});
// Daily standings snapshots for historical tracking
export const teamStandingsSnapshots = pgTable("team_standings_snapshots", {
id: uuid("id").primaryKey().defaultRandom(),
teamId: uuid("team_id")
.notNull()
.references(() => teams.id, { onDelete: "cascade" }),
seasonId: uuid("season_id")
.notNull()
.references(() => seasons.id, { onDelete: "cascade" }),
snapshotDate: date("snapshot_date").notNull(),
totalPoints: decimal("total_points", { precision: 10, scale: 2 }).notNull().default("0"),
rank: integer("rank").notNull(),
// Tiebreaker data
firstPlaceCount: integer("first_place_count").notNull().default(0),
secondPlaceCount: integer("second_place_count").notNull().default(0),
thirdPlaceCount: integer("third_place_count").notNull().default(0),
fourthPlaceCount: integer("fourth_place_count").notNull().default(0),
fifthPlaceCount: integer("fifth_place_count").notNull().default(0),
sixthPlaceCount: integer("sixth_place_count").notNull().default(0),
seventhPlaceCount: integer("seventh_place_count").notNull().default(0),
eighthPlaceCount: integer("eighth_place_count").notNull().default(0),
participantsRemaining: integer("participants_remaining").notNull().default(0),
createdAt: timestamp("created_at").defaultNow().notNull(),
});
// Expected value tracking (league-specific)
export const participantExpectedValues = pgTable("participant_expected_values", {
id: uuid("id").primaryKey().defaultRandom(),
participantId: uuid("participant_id")
.notNull()
.references(() => participants.id, { onDelete: "cascade" }),
seasonId: uuid("season_id")
.notNull()
.references(() => seasons.id, { onDelete: "cascade" }),
// Probability distribution (stored as percentages)
probFirst: decimal("prob_first", { precision: 5, scale: 2 }).notNull().default("0"), // e.g., 15.50 = 15.5%
probSecond: decimal("prob_second", { precision: 5, scale: 2 }).notNull().default("0"),
probThird: decimal("prob_third", { precision: 5, scale: 2 }).notNull().default("0"),
probFourth: decimal("prob_fourth", { precision: 5, scale: 2 }).notNull().default("0"),
probFifth: decimal("prob_fifth", { precision: 5, scale: 2 }).notNull().default("0"),
probSixth: decimal("prob_sixth", { precision: 5, scale: 2 }).notNull().default("0"),
probSeventh: decimal("prob_seventh", { precision: 5, scale: 2 }).notNull().default("0"),
probEighth: decimal("prob_eighth", { precision: 5, scale: 2 }).notNull().default("0"),
// Calculated EV
expectedValue: decimal("expected_value", { precision: 10, scale: 2 }).notNull().default("0"),
calculatedAt: timestamp("calculated_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
// Participant season results (for F1 current points tracking during season)
export const participantSeasonResults = pgTable("participant_season_results", {
id: uuid("id").primaryKey().defaultRandom(),
participantId: uuid("participant_id")
.notNull()
.references(() => participants.id, { onDelete: "cascade" }),
sportsSeasonId: uuid("sports_season_id")
.notNull()
.references(() => sportsSeasons.id, { onDelete: "cascade" }),
currentPoints: decimal("current_points", { precision: 10, scale: 2 }).notNull().default("0"), // Current F1 championship points, etc.
currentPosition: integer("current_position"), // Current standings position
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
// Relations // Relations
export const sportsRelations = relations(sports, ({ many }) => ({ export const sportsRelations = relations(sports, ({ many }) => ({
sportsSeasons: many(sportsSeasons), sportsSeasons: many(sportsSeasons),
@ -388,3 +610,121 @@ export const autodraftSettingsRelations = relations(autodraftSettings, ({ one })
references: [teams.id], references: [teams.id],
}), }),
})); }));
// Scoring System Relations
export const scoringEventsRelations = relations(scoringEvents, ({ one, many }) => ({
sportsSeason: one(sportsSeasons, {
fields: [scoringEvents.sportsSeasonId],
references: [sportsSeasons.id],
}),
eventResults: many(eventResults),
playoffMatches: many(playoffMatches),
}));
export const eventResultsRelations = relations(eventResults, ({ one }) => ({
scoringEvent: one(scoringEvents, {
fields: [eventResults.scoringEventId],
references: [scoringEvents.id],
}),
participant: one(participants, {
fields: [eventResults.participantId],
references: [participants.id],
}),
}));
export const playoffMatchesRelations = relations(playoffMatches, ({ one }) => ({
scoringEvent: one(scoringEvents, {
fields: [playoffMatches.scoringEventId],
references: [scoringEvents.id],
}),
participant1: one(participants, {
fields: [playoffMatches.participant1Id],
references: [participants.id],
}),
participant2: one(participants, {
fields: [playoffMatches.participant2Id],
references: [participants.id],
}),
winner: one(participants, {
fields: [playoffMatches.winnerId],
references: [participants.id],
}),
loser: one(participants, {
fields: [playoffMatches.loserId],
references: [participants.id],
}),
}));
export const participantQualifyingTotalsRelations = relations(participantQualifyingTotals, ({ one }) => ({
participant: one(participants, {
fields: [participantQualifyingTotals.participantId],
references: [participants.id],
}),
sportsSeason: one(sportsSeasons, {
fields: [participantQualifyingTotals.sportsSeasonId],
references: [sportsSeasons.id],
}),
}));
export const qualifyingPointConfigRelations = relations(qualifyingPointConfig, ({ one }) => ({
sportsSeason: one(sportsSeasons, {
fields: [qualifyingPointConfig.sportsSeasonId],
references: [sportsSeasons.id],
}),
}));
export const teamSportScoresRelations = relations(teamSportScores, ({ one }) => ({
team: one(teams, {
fields: [teamSportScores.teamId],
references: [teams.id],
}),
sportsSeason: one(sportsSeasons, {
fields: [teamSportScores.sportsSeasonId],
references: [sportsSeasons.id],
}),
}));
export const teamStandingsRelations = relations(teamStandings, ({ one }) => ({
team: one(teams, {
fields: [teamStandings.teamId],
references: [teams.id],
}),
season: one(seasons, {
fields: [teamStandings.seasonId],
references: [seasons.id],
}),
}));
export const teamStandingsSnapshotsRelations = relations(teamStandingsSnapshots, ({ one }) => ({
team: one(teams, {
fields: [teamStandingsSnapshots.teamId],
references: [teams.id],
}),
season: one(seasons, {
fields: [teamStandingsSnapshots.seasonId],
references: [seasons.id],
}),
}));
export const participantExpectedValuesRelations = relations(participantExpectedValues, ({ one }) => ({
participant: one(participants, {
fields: [participantExpectedValues.participantId],
references: [participants.id],
}),
season: one(seasons, {
fields: [participantExpectedValues.seasonId],
references: [seasons.id],
}),
}));
export const participantSeasonResultsRelations = relations(participantSeasonResults, ({ one }) => ({
participant: one(participants, {
fields: [participantSeasonResults.participantId],
references: [participants.id],
}),
sportsSeason: one(sportsSeasons, {
fields: [participantSeasonResults.sportsSeasonId],
references: [sportsSeasons.id],
}),
}));

View file

@ -0,0 +1,274 @@
CREATE TYPE "public"."event_type" AS ENUM('playoff_game', 'major_tournament', 'race', 'final_standings');--> statement-breakpoint
CREATE TYPE "public"."scoring_pattern" AS ENUM('single_elimination_playoff', 'page_playoff', 'season_standings', 'qualifying_points');--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "event_results" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"scoring_event_id" uuid NOT NULL,
"participant_id" uuid NOT NULL,
"placement" integer,
"qualifying_points_awarded" numeric(10, 2),
"eliminated" boolean,
"raw_score" numeric(10, 2),
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "participant_expected_values" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"participant_id" uuid NOT NULL,
"season_id" uuid NOT NULL,
"prob_first" numeric(5, 2) DEFAULT '0' NOT NULL,
"prob_second" numeric(5, 2) DEFAULT '0' NOT NULL,
"prob_third" numeric(5, 2) DEFAULT '0' NOT NULL,
"prob_fourth" numeric(5, 2) DEFAULT '0' NOT NULL,
"prob_fifth" numeric(5, 2) DEFAULT '0' NOT NULL,
"prob_sixth" numeric(5, 2) DEFAULT '0' NOT NULL,
"prob_seventh" numeric(5, 2) DEFAULT '0' NOT NULL,
"prob_eighth" numeric(5, 2) DEFAULT '0' NOT NULL,
"expected_value" numeric(10, 2) DEFAULT '0' NOT NULL,
"calculated_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "participant_qualifying_totals" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"participant_id" uuid NOT NULL,
"sports_season_id" uuid NOT NULL,
"total_qualifying_points" numeric(10, 2) DEFAULT '0' NOT NULL,
"events_scored" integer DEFAULT 0 NOT NULL,
"final_ranking" integer,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "participant_season_results" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"participant_id" uuid NOT NULL,
"sports_season_id" uuid NOT NULL,
"current_points" numeric(10, 2) DEFAULT '0' NOT NULL,
"current_position" integer,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "playoff_matches" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"scoring_event_id" uuid NOT NULL,
"round" varchar(50) NOT NULL,
"match_number" integer NOT NULL,
"participant1_id" uuid,
"participant2_id" uuid,
"winner_id" uuid,
"loser_id" uuid,
"is_complete" boolean DEFAULT false NOT NULL,
"participant1_score" numeric(10, 2),
"participant2_score" numeric(10, 2),
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "qualifying_point_config" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"sports_season_id" uuid NOT NULL,
"placement" integer NOT NULL,
"points" numeric(10, 2) NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "scoring_events" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"sports_season_id" uuid NOT NULL,
"name" varchar(255) NOT NULL,
"event_date" date,
"event_type" "event_type" NOT NULL,
"playoff_round" varchar(50),
"is_qualifying_event" boolean DEFAULT false NOT NULL,
"is_complete" boolean DEFAULT false NOT NULL,
"completed_at" timestamp,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "team_sport_scores" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"team_id" uuid NOT NULL,
"sports_season_id" uuid NOT NULL,
"total_points" numeric(10, 2) DEFAULT '0' NOT NULL,
"participants_completed" integer DEFAULT 0 NOT NULL,
"participants_total" integer DEFAULT 0 NOT NULL,
"calculated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "team_standings" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"team_id" uuid NOT NULL,
"season_id" uuid NOT NULL,
"total_points" numeric(10, 2) DEFAULT '0' NOT NULL,
"current_rank" integer NOT NULL,
"previous_rank" integer,
"first_place_count" integer DEFAULT 0 NOT NULL,
"second_place_count" integer DEFAULT 0 NOT NULL,
"third_place_count" integer DEFAULT 0 NOT NULL,
"fourth_place_count" integer DEFAULT 0 NOT NULL,
"fifth_place_count" integer DEFAULT 0 NOT NULL,
"sixth_place_count" integer DEFAULT 0 NOT NULL,
"seventh_place_count" integer DEFAULT 0 NOT NULL,
"eighth_place_count" integer DEFAULT 0 NOT NULL,
"participants_remaining" integer DEFAULT 0 NOT NULL,
"calculated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "team_standings_snapshots" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"team_id" uuid NOT NULL,
"season_id" uuid NOT NULL,
"snapshot_date" date NOT NULL,
"total_points" numeric(10, 2) DEFAULT '0' NOT NULL,
"rank" integer NOT NULL,
"first_place_count" integer DEFAULT 0 NOT NULL,
"second_place_count" integer DEFAULT 0 NOT NULL,
"third_place_count" integer DEFAULT 0 NOT NULL,
"fourth_place_count" integer DEFAULT 0 NOT NULL,
"fifth_place_count" integer DEFAULT 0 NOT NULL,
"sixth_place_count" integer DEFAULT 0 NOT NULL,
"seventh_place_count" integer DEFAULT 0 NOT NULL,
"eighth_place_count" integer DEFAULT 0 NOT NULL,
"participants_remaining" integer DEFAULT 0 NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "seasons" ADD COLUMN "points_for_1st" integer DEFAULT 100 NOT NULL;--> statement-breakpoint
ALTER TABLE "seasons" ADD COLUMN "points_for_2nd" integer DEFAULT 70 NOT NULL;--> statement-breakpoint
ALTER TABLE "seasons" ADD COLUMN "points_for_3rd" integer DEFAULT 50 NOT NULL;--> statement-breakpoint
ALTER TABLE "seasons" ADD COLUMN "points_for_4th" integer DEFAULT 40 NOT NULL;--> statement-breakpoint
ALTER TABLE "seasons" ADD COLUMN "points_for_5th" integer DEFAULT 25 NOT NULL;--> statement-breakpoint
ALTER TABLE "seasons" ADD COLUMN "points_for_6th" integer DEFAULT 25 NOT NULL;--> statement-breakpoint
ALTER TABLE "seasons" ADD COLUMN "points_for_7th" integer DEFAULT 15 NOT NULL;--> statement-breakpoint
ALTER TABLE "seasons" ADD COLUMN "points_for_8th" integer DEFAULT 15 NOT NULL;--> statement-breakpoint
ALTER TABLE "sports_seasons" ADD COLUMN "scoring_pattern" "scoring_pattern";--> statement-breakpoint
ALTER TABLE "sports_seasons" ADD COLUMN "total_majors" integer;--> statement-breakpoint
ALTER TABLE "sports_seasons" ADD COLUMN "majors_completed" integer DEFAULT 0 NOT NULL;--> statement-breakpoint
ALTER TABLE "sports_seasons" ADD COLUMN "qualifying_points_finalized" boolean DEFAULT false NOT NULL;--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "event_results" ADD CONSTRAINT "event_results_scoring_event_id_scoring_events_id_fk" FOREIGN KEY ("scoring_event_id") REFERENCES "public"."scoring_events"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "event_results" ADD CONSTRAINT "event_results_participant_id_participants_id_fk" FOREIGN KEY ("participant_id") REFERENCES "public"."participants"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "participant_expected_values" ADD CONSTRAINT "participant_expected_values_participant_id_participants_id_fk" FOREIGN KEY ("participant_id") REFERENCES "public"."participants"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "participant_expected_values" ADD CONSTRAINT "participant_expected_values_season_id_seasons_id_fk" FOREIGN KEY ("season_id") REFERENCES "public"."seasons"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "participant_qualifying_totals" ADD CONSTRAINT "participant_qualifying_totals_participant_id_participants_id_fk" FOREIGN KEY ("participant_id") REFERENCES "public"."participants"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "participant_qualifying_totals" ADD CONSTRAINT "participant_qualifying_totals_sports_season_id_sports_seasons_id_fk" FOREIGN KEY ("sports_season_id") REFERENCES "public"."sports_seasons"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "participant_season_results" ADD CONSTRAINT "participant_season_results_participant_id_participants_id_fk" FOREIGN KEY ("participant_id") REFERENCES "public"."participants"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "participant_season_results" ADD CONSTRAINT "participant_season_results_sports_season_id_sports_seasons_id_fk" FOREIGN KEY ("sports_season_id") REFERENCES "public"."sports_seasons"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "playoff_matches" ADD CONSTRAINT "playoff_matches_scoring_event_id_scoring_events_id_fk" FOREIGN KEY ("scoring_event_id") REFERENCES "public"."scoring_events"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "playoff_matches" ADD CONSTRAINT "playoff_matches_participant1_id_participants_id_fk" FOREIGN KEY ("participant1_id") REFERENCES "public"."participants"("id") ON DELETE set null ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "playoff_matches" ADD CONSTRAINT "playoff_matches_participant2_id_participants_id_fk" FOREIGN KEY ("participant2_id") REFERENCES "public"."participants"("id") ON DELETE set null ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "playoff_matches" ADD CONSTRAINT "playoff_matches_winner_id_participants_id_fk" FOREIGN KEY ("winner_id") REFERENCES "public"."participants"("id") ON DELETE set null ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "playoff_matches" ADD CONSTRAINT "playoff_matches_loser_id_participants_id_fk" FOREIGN KEY ("loser_id") REFERENCES "public"."participants"("id") ON DELETE set null ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "qualifying_point_config" ADD CONSTRAINT "qualifying_point_config_sports_season_id_sports_seasons_id_fk" FOREIGN KEY ("sports_season_id") REFERENCES "public"."sports_seasons"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "scoring_events" ADD CONSTRAINT "scoring_events_sports_season_id_sports_seasons_id_fk" FOREIGN KEY ("sports_season_id") REFERENCES "public"."sports_seasons"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "team_sport_scores" ADD CONSTRAINT "team_sport_scores_team_id_teams_id_fk" FOREIGN KEY ("team_id") REFERENCES "public"."teams"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "team_sport_scores" ADD CONSTRAINT "team_sport_scores_sports_season_id_sports_seasons_id_fk" FOREIGN KEY ("sports_season_id") REFERENCES "public"."sports_seasons"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "team_standings" ADD CONSTRAINT "team_standings_team_id_teams_id_fk" FOREIGN KEY ("team_id") REFERENCES "public"."teams"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "team_standings" ADD CONSTRAINT "team_standings_season_id_seasons_id_fk" FOREIGN KEY ("season_id") REFERENCES "public"."seasons"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "team_standings_snapshots" ADD CONSTRAINT "team_standings_snapshots_team_id_teams_id_fk" FOREIGN KEY ("team_id") REFERENCES "public"."teams"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "team_standings_snapshots" ADD CONSTRAINT "team_standings_snapshots_season_id_seasons_id_fk" FOREIGN KEY ("season_id") REFERENCES "public"."seasons"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;

File diff suppressed because it is too large Load diff

View file

@ -141,6 +141,13 @@
"when": 1761112236540, "when": 1761112236540,
"tag": "0019_acoustic_ben_grimm", "tag": "0019_acoustic_ben_grimm",
"breakpoints": true "breakpoints": true
},
{
"idx": 20,
"version": "7",
"when": 1761719248881,
"tag": "0020_slim_spacker_dave",
"breakpoints": true
} }
] ]
} }