-- ================================================
-- Fix for ActivityLogs Index
-- Run this separately to create the missing index
-- ================================================
--
-- This creates the ActivityLogs index that couldn't be created
-- from within the main migration script due to PostgreSQL
-- limitations with CONCURRENT operations in functions.
--
-- ================================================

-- Create the ActivityLogs index
-- This will error gracefully if the table doesn't exist
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_activitylogs_userid_datecreated
ON activitylog."ActivityLogs" ("UserId", "DateCreated" DESC)
WHERE "UserId" IS NOT NULL;

-- Verify it was created
SELECT 
    schemaname AS "Schema",
    tablename AS "Table",
    indexname AS "Index Name",
    indexdef AS "Definition"
FROM pg_indexes
WHERE indexname = 'idx_activitylogs_userid_datecreated';

-- Expected: 1 row showing the index on activitylog.ActivityLogs
