brackt/drizzle/0069_draft_window.sql

20 lines
843 B
MySQL
Raw Normal View History

-- 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
-- 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
UPDATE "sports_seasons"
SET "draft_on" = '2020-01-01', "draft_off" = '2020-12-31'
WHERE "is_draftable" = false;--> 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";