37 lines
1.7 KiB
SQL
37 lines
1.7 KiB
SQL
-- SQL Migration: Add 'comet' type support to celestial_bodies table
|
|
--
|
|
-- Purpose: Enable comet celestial body type in the database
|
|
--
|
|
-- Note: The CheckConstraint in the ORM model (celestial_body.py line 37) already includes 'comet',
|
|
-- but if the database was created before this was added, we need to update the constraint.
|
|
--
|
|
-- Instructions:
|
|
-- 1. Check if the constraint already includes 'comet':
|
|
-- SELECT conname, pg_get_constraintdef(oid)
|
|
-- FROM pg_constraint
|
|
-- WHERE conrelid = 'celestial_bodies'::regclass AND conname = 'chk_type';
|
|
--
|
|
-- 2. If 'comet' is NOT in the constraint, run the following migration:
|
|
|
|
-- Step 1: Drop the existing constraint
|
|
ALTER TABLE celestial_bodies DROP CONSTRAINT IF EXISTS chk_type;
|
|
|
|
-- Step 2: Recreate the constraint with 'comet' included
|
|
ALTER TABLE celestial_bodies
|
|
ADD CONSTRAINT chk_type
|
|
CHECK (type IN ('star', 'planet', 'moon', 'probe', 'comet', 'asteroid', 'dwarf_planet', 'satellite'));
|
|
|
|
-- Step 3: Verify the constraint was updated successfully
|
|
SELECT conname, pg_get_constraintdef(oid)
|
|
FROM pg_constraint
|
|
WHERE conrelid = 'celestial_bodies'::regclass AND conname = 'chk_type';
|
|
|
|
-- Expected output should show:
|
|
-- chk_type | CHECK ((type)::text = ANY (ARRAY[('star'::character varying)::text, ('planet'::character varying)::text, ('moon'::character varying)::text, ('probe'::character varying)::text, ('comet'::character varying)::text, ('asteroid'::character varying)::text, ('dwarf_planet'::character varying)::text, ('satellite'::character varying)::text]))
|
|
|
|
-- ROLLBACK (if needed):
|
|
-- ALTER TABLE celestial_bodies DROP CONSTRAINT IF EXISTS chk_type;
|
|
-- ALTER TABLE celestial_bodies
|
|
-- ADD CONSTRAINT chk_type
|
|
-- CHECK (type IN ('star', 'planet', 'moon', 'probe', 'asteroid', 'dwarf_planet', 'satellite'));
|