CREATE TYPE "public"."picked_by_type" AS ENUM('owner', 'commissioner', 'auto');--> statement-breakpoint CREATE TABLE IF NOT EXISTS "draft_picks" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "season_id" uuid NOT NULL, "team_id" uuid NOT NULL, "participant_id" uuid NOT NULL, "pick_number" integer NOT NULL, "round" integer NOT NULL, "pick_in_round" integer NOT NULL, "picked_by_user_id" varchar(255) NOT NULL, "picked_by_type" "picked_by_type" NOT NULL, "time_used" integer DEFAULT 0 NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE IF NOT EXISTS "draft_queue" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "season_id" uuid NOT NULL, "team_id" uuid NOT NULL, "participant_id" uuid NOT NULL, "queue_position" integer NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE IF NOT EXISTS "draft_timers" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "season_id" uuid NOT NULL, "team_id" uuid NOT NULL, "time_remaining" integer NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint ALTER TABLE "seasons" ADD COLUMN "draft_initial_time" integer DEFAULT 120 NOT NULL;--> statement-breakpoint ALTER TABLE "seasons" ADD COLUMN "draft_increment_time" integer DEFAULT 30 NOT NULL;--> statement-breakpoint ALTER TABLE "seasons" ADD COLUMN "current_pick_number" integer DEFAULT 1;--> statement-breakpoint ALTER TABLE "seasons" ADD COLUMN "draft_started_at" timestamp;--> statement-breakpoint ALTER TABLE "seasons" ADD COLUMN "draft_paused" boolean DEFAULT false NOT NULL;--> statement-breakpoint DO $$ BEGIN ALTER TABLE "draft_picks" ADD CONSTRAINT "draft_picks_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 "draft_picks" ADD CONSTRAINT "draft_picks_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 "draft_picks" ADD CONSTRAINT "draft_picks_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 "draft_queue" ADD CONSTRAINT "draft_queue_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 "draft_queue" ADD CONSTRAINT "draft_queue_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 "draft_queue" ADD CONSTRAINT "draft_queue_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 "draft_timers" ADD CONSTRAINT "draft_timers_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 "draft_timers" ADD CONSTRAINT "draft_timers_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 $$;