2026-03-07 21:59:29 -08:00
|
|
|
-- Consolidate single_elimination_playoff and page_playoff → playoff_bracket
|
|
|
|
|
-- PostgreSQL does not support DROP VALUE on enums, so we recreate the type.
|
2026-03-09 15:34:31 -07:00
|
|
|
-- Wrapped in DO block so re-running is safe if already applied.
|
2026-03-07 21:59:29 -08:00
|
|
|
|
2026-03-09 15:34:31 -07:00
|
|
|
DO $$
|
|
|
|
|
BEGIN
|
|
|
|
|
-- Only migrate if the old enum values still exist
|
|
|
|
|
IF EXISTS (
|
|
|
|
|
SELECT 1 FROM pg_enum
|
|
|
|
|
WHERE enumlabel = 'single_elimination_playoff'
|
|
|
|
|
AND enumtypid = (SELECT oid FROM pg_type WHERE typname = 'scoring_pattern')
|
|
|
|
|
) THEN
|
|
|
|
|
-- Step 1: Create new consolidated enum
|
|
|
|
|
CREATE TYPE "scoring_pattern_new" AS ENUM('playoff_bracket', 'season_standings', 'qualifying_points');
|
2026-03-07 21:59:29 -08:00
|
|
|
|
2026-03-09 15:34:31 -07:00
|
|
|
-- Step 2: Migrate column data, mapping old values to playoff_bracket
|
|
|
|
|
ALTER TABLE "sports_seasons"
|
|
|
|
|
ALTER COLUMN "scoring_pattern" TYPE "scoring_pattern_new"
|
|
|
|
|
USING (
|
|
|
|
|
CASE scoring_pattern::text
|
|
|
|
|
WHEN 'single_elimination_playoff' THEN 'playoff_bracket'::scoring_pattern_new
|
|
|
|
|
WHEN 'page_playoff' THEN 'playoff_bracket'::scoring_pattern_new
|
|
|
|
|
ELSE scoring_pattern::text::scoring_pattern_new
|
|
|
|
|
END
|
|
|
|
|
);
|
2026-03-07 21:59:29 -08:00
|
|
|
|
2026-03-09 15:34:31 -07:00
|
|
|
-- Step 3: Replace old type
|
|
|
|
|
DROP TYPE "scoring_pattern";
|
|
|
|
|
ALTER TYPE "scoring_pattern_new" RENAME TO "scoring_pattern";
|
|
|
|
|
END IF;
|
|
|
|
|
END $$;
|