Files
Sauci/apps/supabase/migrations/20260102000002_add_feature_interest_counts_rpc.sql
T
jjbrunton 494ed17fe2 Add streaks, scheduled releases, and notification settings
- Couple streaks with milestone notifications
- Scheduled pack releases with admin UI
- Notification preferences screen
- Refactored profile settings screens
- Partner activity notifications
2026-01-17 16:38:47 +00:00

29 lines
765 B
PL/PgSQL

-- Expose per-feature opt-in counts for admins
CREATE OR REPLACE FUNCTION public.get_feature_interest_counts()
RETURNS TABLE (
feature_name TEXT,
opt_in_count BIGINT,
opt_in_count_last_7_days BIGINT
)
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = 'public'
AS $$
BEGIN
IF NOT has_permission('view_users') THEN
RAISE EXCEPTION 'Access denied';
END IF;
RETURN QUERY
SELECT
fi.feature_name,
COUNT(*)::BIGINT AS opt_in_count,
COUNT(*) FILTER (WHERE fi.created_at >= now() - interval '7 days')::BIGINT AS opt_in_count_last_7_days
FROM public.feature_interests fi
GROUP BY fi.feature_name
ORDER BY opt_in_count DESC, fi.feature_name ASC;
END;
$$;
GRANT EXECUTE ON FUNCTION public.get_feature_interest_counts() TO authenticated;