The migration system was broken due to three issues: 1. Snapshot 0067 had an invalid `autoincrement` field (PostgreSQL doesn't support this) causing Zod validation to fail with "data is malformed" 2. Migrations 0068 and 0069 were missing snapshot files, breaking the snapshot chain required by `drizzle-kit generate` 3. Orphaned file 0048_mean_enchantress.sql existed outside the journal Fixed by removing the invalid field, regenerating migrations 0068-0069 with proper snapshots via `drizzle-kit generate`, deleting the orphaned file, and adding a no-op verification migration (0070). Made migration 0069 idempotent with IF EXISTS/IF NOT EXISTS guards for production safety. Updated CLAUDE.md with rules to prevent manual migration/journal editing and ensure snapshots are always generated. https://claude.ai/code/session_01JuVHpRPa974MKSHoXNGkgU
18 lines
1.1 KiB
SQL
18 lines
1.1 KiB
SQL
-- Step 1: Add new columns as nullable (IF NOT EXISTS for idempotency)
|
|
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 (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;
|
|
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 (IF EXISTS for idempotency)
|
|
ALTER TABLE "sports_seasons" DROP COLUMN IF EXISTS "is_draftable";
|