diff --git a/drizzle/0069_draft_window.sql b/drizzle/0069_draft_window.sql index fe4bf4c..b241a1e 100644 --- a/drizzle/0069_draft_window.sql +++ b/drizzle/0069_draft_window.sql @@ -1,19 +1,27 @@ -- Step 1: Add new columns as nullable -ALTER TABLE "sports_seasons" ADD COLUMN "draft_on" date;--> statement-breakpoint -ALTER TABLE "sports_seasons" ADD COLUMN "draft_off" date;--> statement-breakpoint +ALTER TABLE "sports_seasons" ADD COLUMN IF NOT EXISTS "draft_on" date;--> statement-breakpoint +ALTER TABLE "sports_seasons" ADD COLUMN IF NOT EXISTS "draft_off" date;--> statement-breakpoint --- Step 2: Backfill data based on existing is_draftable flag -UPDATE "sports_seasons" -SET "draft_on" = '2026-04-06', "draft_off" = '2099-12-31' -WHERE "is_draftable" = true;--> statement-breakpoint +-- Step 2: Backfill data based on existing is_draftable flag (only if column still exists) +DO $$ +BEGIN + IF EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_name = 'sports_seasons' AND column_name = 'is_draftable' + ) THEN + UPDATE "sports_seasons" + SET "draft_on" = '2026-04-06', "draft_off" = '2099-12-31' + WHERE "is_draftable" = true; -UPDATE "sports_seasons" -SET "draft_on" = '2020-01-01', "draft_off" = '2020-12-31' -WHERE "is_draftable" = false;--> statement-breakpoint + UPDATE "sports_seasons" + SET "draft_on" = '2020-01-01', "draft_off" = '2020-12-31' + WHERE "is_draftable" = false; + END IF; +END $$;--> statement-breakpoint -- Step 3: Apply NOT NULL constraints ALTER TABLE "sports_seasons" ALTER COLUMN "draft_on" SET NOT NULL;--> statement-breakpoint ALTER TABLE "sports_seasons" ALTER COLUMN "draft_off" SET NOT NULL;--> statement-breakpoint -- Step 4: Drop old column -ALTER TABLE "sports_seasons" DROP COLUMN "is_draftable"; +ALTER TABLE "sports_seasons" DROP COLUMN IF EXISTS "is_draftable"; diff --git a/drizzle/0070_game_scheduled_date.sql b/drizzle/0070_game_scheduled_date.sql new file mode 100644 index 0000000..c7f921f --- /dev/null +++ b/drizzle/0070_game_scheduled_date.sql @@ -0,0 +1,4 @@ +ALTER TABLE "playoff_match_games" ADD COLUMN "scheduled_date" date;--> statement-breakpoint +UPDATE "playoff_match_games" +SET "scheduled_date" = DATE("scheduled_at" AT TIME ZONE 'UTC') +WHERE "scheduled_at" IS NOT NULL;