begin;

grant usage on schema public to authenticated;
grant usage on schema public to service_role;

grant execute on function public.current_app_user_id() to authenticated;
grant execute on function public.current_app_user_id() to service_role;

grant select on table public.users to authenticated;
grant select on table public.api_sessions to authenticated;
grant select on table public.beta_invite_redemptions to authenticated;
grant select on table public.subscriptions to authenticated;
grant select on table public.orders to authenticated;
grant select on table public.entitlements to authenticated;
grant select on table public.quota_buckets to authenticated;
grant select on table public.usage_ledger to authenticated;
grant select on table public.pet_profiles to authenticated;
grant select on table public.consent_records to authenticated;
grant select on table public.pet_media to authenticated;
grant select on table public.pet_builds to authenticated;
grant select on table public.provider_call_metrics to authenticated;
grant select on table public.pet_packages to authenticated;
grant select on table public.deletion_requests to authenticated;
grant select on table public.events to authenticated;

grant all privileges on table public.users to service_role;
grant all privileges on table public.api_sessions to service_role;
grant all privileges on table public.beta_invites to service_role;
grant all privileges on table public.beta_invite_redemptions to service_role;
grant all privileges on table public.price_plans to service_role;
grant all privileges on table public.subscriptions to service_role;
grant all privileges on table public.orders to service_role;
grant all privileges on table public.webhook_events to service_role;
grant all privileges on table public.entitlements to service_role;
grant all privileges on table public.quota_buckets to service_role;
grant all privileges on table public.usage_ledger to service_role;
grant all privileges on table public.pet_profiles to service_role;
grant all privileges on table public.consent_records to service_role;
grant all privileges on table public.pet_media to service_role;
grant all privileges on table public.pet_builds to service_role;
grant all privileges on table public.provider_call_metrics to service_role;
grant all privileges on table public.pet_packages to service_role;
grant all privileges on table public.deletion_requests to service_role;
grant all privileges on table public.events to service_role;
grant all privileges on table public.audit_logs to service_role;

commit;
