Fix idempotency on 0069
This commit is contained in:
parent
90127fe5bd
commit
b19445f2fe
2 changed files with 22 additions and 10 deletions
|
|
@ -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
|
||||
-- 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;--> statement-breakpoint
|
||||
WHERE "is_draftable" = true;
|
||||
|
||||
UPDATE "sports_seasons"
|
||||
SET "draft_on" = '2020-01-01', "draft_off" = '2020-12-31'
|
||||
WHERE "is_draftable" = false;--> statement-breakpoint
|
||||
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";
|
||||
|
|
|
|||
4
drizzle/0070_game_scheduled_date.sql
Normal file
4
drizzle/0070_game_scheduled_date.sql
Normal file
|
|
@ -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;
|
||||
Loading…
Add table
Reference in a new issue