-- ============================================
-- Database Security Optimization: Search Path
-- ============================================
-- Addresses "function_search_path_mutable" security warnings
-- ============================================

-- Fix for handle_new_user
ALTER FUNCTION public.handle_new_user() SET search_path = '';

-- Fix for generate_buddy_code
-- If this function exists, update its search_path
DO $$ 
BEGIN
    IF EXISTS (SELECT 1 FROM pg_proc WHERE proname = 'generate_buddy_code') THEN
        ALTER FUNCTION public.generate_buddy_code() SET search_path = '';
    END IF;
END $$;

-- Fix for check_session_access
-- If this function exists, update its search_path
DO $$ 
BEGIN
    IF EXISTS (SELECT 1 FROM pg_proc WHERE proname = 'check_session_access') THEN
        BEGIN
            ALTER FUNCTION public.check_session_access(uuid) SET search_path = '';
            -- Note: If it has different arguments, you might need to adjust the signature above
        EXCEPTION WHEN OTHERS THEN
            RAISE NOTICE 'Could not set search_path for check_session_access: %', SQLERRM;
        END;
    END IF;
END $$;
