brackt/drizzle/0054_massive_vulcan.sql
Chris Parsons bcca8b76fa
Add regular season standings for NBA/NHL (fixes #89) (#192)
Adds live standings sync and display for bracket-based sports (NBA/NHL),
so league members can see W/L tables and which teams their opponents drafted
during the regular season — not just after the playoff bracket is set.

- New `regular_season_standings` table with upsert-on-conflict sync
- Standings sync service with NHL (api-web.nhle.com) and NBA (ESPN) adapters,
  externalId write-back for future syncs, and unmatched-team resolution UI
- `RegularSeasonStandings` component: flat (NBA) + division/wild-card (NHL) modes,
  playoff line, TeamOwnerBadge, projected Brackt points (EV), mobile horizontal scroll
- Admin "Sync Standings" card + "Resolve Unmatched" UI on sports season page
- Admin manual standings edit hatch at /admin/sports-seasons/:id/regular-standings
- Show standings above bracket until matches exist; below once bracket is set
- `normalize-team-name` utility extracted to shared lib

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 00:12:01 -07:00

39 lines
No EOL
1.6 KiB
SQL

CREATE TABLE IF NOT EXISTS "regular_season_standings" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"participant_id" uuid NOT NULL,
"sports_season_id" uuid NOT NULL,
"wins" integer DEFAULT 0 NOT NULL,
"losses" integer DEFAULT 0 NOT NULL,
"ot_losses" integer,
"ties" integer,
"win_pct" numeric(5, 4),
"games_played" integer DEFAULT 0 NOT NULL,
"games_back" numeric(5, 1),
"conference" varchar(100),
"division" varchar(100),
"conference_rank" integer,
"division_rank" integer,
"league_rank" integer,
"streak" varchar(20),
"last_ten" varchar(15),
"home_record" varchar(15),
"away_record" varchar(15),
"external_team_id" varchar(255),
"synced_at" timestamp,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "regular_season_standings" ADD CONSTRAINT "regular_season_standings_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 "regular_season_standings" ADD CONSTRAINT "regular_season_standings_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
CREATE UNIQUE INDEX IF NOT EXISTS "rss_participant_season_idx" ON "regular_season_standings" USING btree ("participant_id","sports_season_id");