-- Migration: Add overall_end_time to activities table
-- Date: 2026-04-13
-- Description: Add overall_end_time column for activity overall end time management

-- Add overall_end_time column to activities if it doesn't exist
DO $$
BEGIN
    IF NOT EXISTS (
        SELECT 1 FROM information_schema.columns
        WHERE table_name = 'activities' AND column_name = 'overall_end_time'
    ) THEN
        ALTER TABLE activities ADD COLUMN overall_end_time BIGINT DEFAULT 0;
        RAISE NOTICE 'Column overall_end_time added to activities table';
    ELSE
        RAISE NOTICE 'Column overall_end_time already exists in activities table';
    END IF;
END $$;

-- Add avatar_url column to fan_profiles if it doesn't exist
DO $$
BEGIN
    IF NOT EXISTS (
        SELECT 1 FROM information_schema.columns
        WHERE table_name = 'fan_profiles' AND column_name = 'avatar_url'
    ) THEN
        ALTER TABLE fan_profiles ADD COLUMN avatar_url VARCHAR(500);
        RAISE NOTICE 'Column avatar_url added to fan_profiles table';
    ELSE
        RAISE NOTICE 'Column avatar_url already exists in fan_profiles table';
    END IF;
END $$;

-- Add is_original column to assets if it doesn't exist
DO $$
BEGIN
    IF NOT EXISTS (
        SELECT 1 FROM information_schema.columns
        WHERE table_name = 'assets' AND column_name = 'is_original'
    ) THEN
        ALTER TABLE assets ADD COLUMN is_original BOOLEAN DEFAULT false;
        RAISE NOTICE 'Column is_original added to assets table';
    ELSE
        RAISE NOTICE 'Column is_original already exists in assets table';
    END IF;
END $$;

-- Add theme column to activities if it doesn't exist
DO $$
BEGIN
    IF NOT EXISTS (
        SELECT 1 FROM information_schema.columns
        WHERE table_name = 'activities' AND column_name = 'theme'
    ) THEN
        ALTER TABLE activities ADD COLUMN theme VARCHAR(100);
        RAISE NOTICE 'Column theme added to activities table';
    ELSE
        RAISE NOTICE 'Column theme already exists in activities table';
    END IF;
END $$;

-- Migration complete
DO $$
BEGIN
    RAISE NOTICE 'Migration completed successfully';
END $$;
