-- =====================================================================================
-- Admin 用户统计模块 - 权限与依赖函数验证（测试/回归）
-- 目的：在部署/联调前快速确认 get_current_user_role 与性别分布 RPC 是否存在
-- =====================================================================================

-- 1) 检查 get_current_user_role 是否存在（权威依赖）
SELECT n.nspname AS schema, p.proname AS name
FROM pg_proc p
JOIN pg_namespace n ON n.oid = p.pronamespace
WHERE p.proname = 'get_current_user_role'
ORDER BY 1, 2;

-- 2) 检查性别分布 RPC 是否存在
SELECT n.nspname AS schema, p.proname AS name
FROM pg_proc p
JOIN pg_namespace n ON n.oid = p.pronamespace
WHERE p.proname = 'rpc_analytics_user_gender_distribution'
ORDER BY 1, 2;

-- 3) 字段检查：ak_users 是否存在 auth_id 与 role（供 get_current_user_role 使用）
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_schema='public'
  AND table_name='ak_users'
  AND column_name IN ('auth_id','role')
ORDER BY column_name;
