CREATE TABLE IF NOT EXISTS "pending_standings_mappings" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"sports_season_id" uuid NOT NULL,
	"external_team_id" varchar(255) NOT NULL,
	"team_name" varchar(255) NOT NULL,
	"standing_data" jsonb NOT NULL,
	"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
DO $$ BEGIN
 ALTER TABLE "pending_standings_mappings" ADD CONSTRAINT "pending_standings_mappings_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 "psm_season_external_id_idx" ON "pending_standings_mappings" USING btree ("sports_season_id","external_team_id");