sojorn/_legacy/supabase/migrations/20260120_notification_rpc.sql
2026-02-15 00:33:24 -06:00

25 lines
687 B
PL/PgSQL

-- ============================================================================
-- NOTIFICATION RPC FUNCTIONS
-- Helper functions for notification queries
-- ============================================================================
-- Get unread notification count for a user
create or replace function get_unread_notification_count(p_user_id uuid)
returns integer
language plpgsql
stable
security definer
as $$
begin
return (
select count(*)::integer
from notifications
where user_id = p_user_id
and is_read = false
);
end;
$$;
-- Grant execute permission to authenticated users
grant execute on function get_unread_notification_count(uuid) to authenticated;