Brand Studio docs
Engineering manualDatabase declarations

supabase-brand-studio-monitoring-credit-view

Exact checked-in database declaration: docs/supabase-brand-studio-monitoring-credit-view.sql

Source: docs/supabase-brand-studio-monitoring-credit-view.sql. Declared objects: function:brand_studio_ledger_snapshot. This is repository DDL, not a claim about live deployment.

All database declarations · Data structures and lineage

-- Preserve the complete atomic ledger read and expose the immutable metadata
-- needed to distinguish an actual signup grant from configured beta copy.
CREATE OR REPLACE FUNCTION public.brand_studio_ledger_snapshot(p_user_id uuid)
RETURNS jsonb LANGUAGE sql STABLE SECURITY INVOKER SET search_path = '' AS $$
  WITH rows AS MATERIALIZED (
    SELECT kind,amount,pull_id,user_id,idempotency_key,created_at
    FROM public.brand_studio_credit_ledger
    WHERE user_id=p_user_id ORDER BY id LIMIT 100001
  )
  SELECT CASE WHEN count(*)>100000 THEN jsonb_build_object('error','ledger_limit_exceeded')
    ELSE jsonb_build_object('entries',coalesce(jsonb_agg(to_jsonb(rows)), '[]'::jsonb),
      'row_count',count(*),'snapshot_at',statement_timestamp()) END FROM rows;
$$;
REVOKE ALL ON FUNCTION public.brand_studio_ledger_snapshot(uuid) FROM PUBLIC,anon,authenticated;
GRANT EXECUTE ON FUNCTION public.brand_studio_ledger_snapshot(uuid) TO service_role;