-- Script to manually apply externalEventId migration
-- Run this directly on your PostgreSQL database

-- Check if columns exist
SELECT 
    column_name, 
    data_type 
FROM information_schema.columns 
WHERE table_name = 'Event' 
AND column_name IN ('externalEventId', 'externalEventUrl');

-- Add externalEventId column if it doesn't exist
DO $$ 
BEGIN
    IF NOT EXISTS (
        SELECT 1 FROM information_schema.columns 
        WHERE table_name = 'Event' AND column_name = 'externalEventId'
    ) THEN
        ALTER TABLE "Event" ADD COLUMN "externalEventId" TEXT;
        RAISE NOTICE 'Added externalEventId column';
    ELSE
        RAISE NOTICE 'externalEventId column already exists';
    END IF;
END $$;

-- Add externalEventUrl column if it doesn't exist
DO $$ 
BEGIN
    IF NOT EXISTS (
        SELECT 1 FROM information_schema.columns 
        WHERE table_name = 'Event' AND column_name = 'externalEventUrl'
    ) THEN
        ALTER TABLE "Event" ADD COLUMN "externalEventUrl" TEXT;
        RAISE NOTICE 'Added externalEventUrl column';
    ELSE
        RAISE NOTICE 'externalEventUrl column already exists';
    END IF;
END $$;

-- Create index on externalEventId if it doesn't exist
CREATE INDEX IF NOT EXISTS "Event_externalEventId_idx" ON "Event"("externalEventId");

-- Verify columns were added
SELECT 
    column_name, 
    data_type 
FROM information_schema.columns 
WHERE table_name = 'Event' 
AND column_name IN ('externalEventId', 'externalEventUrl');
