Files
membership-be/migrations/add_calendar_uid.sql
2025-12-10 17:52:32 +07:00

39 lines
1.3 KiB
SQL

-- Migration: Add calendar_uid to events table and remove Microsoft Calendar columns
-- Sprint 2: Universal Calendar Export
-- Add new calendar_uid column
ALTER TABLE events ADD COLUMN IF NOT EXISTS calendar_uid VARCHAR;
-- Remove old Microsoft Calendar columns (if they exist)
ALTER TABLE events DROP COLUMN IF EXISTS microsoft_calendar_id;
ALTER TABLE events DROP COLUMN IF EXISTS microsoft_calendar_sync_enabled;
-- Verify migration
DO $$
BEGIN
-- Check if calendar_uid exists
IF EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_name = 'events' AND column_name = 'calendar_uid'
) THEN
RAISE NOTICE '✅ calendar_uid column added successfully';
ELSE
RAISE NOTICE '⚠️ calendar_uid column not found';
END IF;
-- Check if old columns are removed
IF NOT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_name = 'events' AND column_name = 'microsoft_calendar_id'
) THEN
RAISE NOTICE '✅ microsoft_calendar_id column removed';
END IF;
IF NOT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_name = 'events' AND column_name = 'microsoft_calendar_sync_enabled'
) THEN
RAISE NOTICE '✅ microsoft_calendar_sync_enabled column removed';
END IF;
END $$;