-- =============================================================================
-- Migration: Optimize user_sessions indexes
-- Description: Remove optional indexes from user_sessions to improve INSERT performance
-- Reason: 10 indexes were causing 12+ second delays on session creation during login
--          Kept only 5 critical indexes: access_token_hash, expires_at, refresh_token_hash, status, user_id
-- Removed: device_id, tenant_id, token_version, user_platform_active, user_platform_revoked
-- =============================================================================

-- Drop optional indexes
DROP INDEX IF EXISTS idx_user_sessions_device_id;
DROP INDEX IF EXISTS idx_user_sessions_tenant_id;
DROP INDEX IF EXISTS idx_user_sessions_token_version;
DROP INDEX IF EXISTS idx_user_sessions_user_platform_active;
DROP INDEX IF EXISTS idx_user_sessions_user_platform_revoked;

-- Verify remaining indexes (should be 5 critical indexes)
SELECT 
    indexname, 
    tablename 
FROM 
    pg_indexes 
WHERE 
    tablename = 'user_sessions' 
    AND schemaname = 'public';
