-- Fix hash_session_ip to use pgcrypto from extensions schema
CREATE OR REPLACE FUNCTION public.hash_session_ip(session_ip inet)
RETURNS text
LANGUAGE plpgsql
IMMUTABLE
SET search_path = 'public', 'extensions'
AS $$
BEGIN
  -- Return last 8 chars of SHA256 hash with asterisks prefix for privacy
  RETURN '****' || RIGHT(encode(digest(session_ip::text || 'session_salt_2025', 'sha256'), 'hex'), 8);
END;
$$;