-- =============================================================================
-- AgenciaPsi — Row Level Security Policies
-- =============================================================================

ALTER TABLE auth.audit_log_entries ENABLE ROW LEVEL SECURITY;

--
-- Name: flow_state; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.flow_state ENABLE ROW LEVEL SECURITY;

--
-- Name: identities; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.identities ENABLE ROW LEVEL SECURITY;

--
-- Name: instances; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.instances ENABLE ROW LEVEL SECURITY;

--
-- Name: mfa_amr_claims; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.mfa_amr_claims ENABLE ROW LEVEL SECURITY;

--
-- Name: mfa_challenges; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.mfa_challenges ENABLE ROW LEVEL SECURITY;

--
-- Name: mfa_factors; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.mfa_factors ENABLE ROW LEVEL SECURITY;

--
-- Name: one_time_tokens; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.one_time_tokens ENABLE ROW LEVEL SECURITY;

--
-- Name: refresh_tokens; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.refresh_tokens ENABLE ROW LEVEL SECURITY;

--
-- Name: saml_providers; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.saml_providers ENABLE ROW LEVEL SECURITY;

--
-- Name: saml_relay_states; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.saml_relay_states ENABLE ROW LEVEL SECURITY;

--
-- Name: schema_migrations; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.schema_migrations ENABLE ROW LEVEL SECURITY;

--
-- Name: sessions; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.sessions ENABLE ROW LEVEL SECURITY;

--
-- Name: sso_domains; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.sso_domains ENABLE ROW LEVEL SECURITY;

--
-- Name: sso_providers; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.sso_providers ENABLE ROW LEVEL SECURITY;

--
-- Name: users; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.users ENABLE ROW LEVEL SECURITY;

--
-- Name: addon_credits; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.addon_credits ENABLE ROW LEVEL SECURITY;

--
-- Name: addon_credits addon_credits_admin_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY addon_credits_admin_select ON public.addon_credits FOR SELECT TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.saas_admins
  WHERE (saas_admins.user_id = auth.uid()))));


--
-- Name: addon_credits addon_credits_admin_write; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY addon_credits_admin_write ON public.addon_credits TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.saas_admins
  WHERE (saas_admins.user_id = auth.uid())))) WITH CHECK ((EXISTS ( SELECT 1
   FROM public.saas_admins
  WHERE (saas_admins.user_id = auth.uid()))));


--
-- Name: addon_credits addon_credits_select_own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY addon_credits_select_own ON public.addon_credits FOR SELECT TO authenticated USING ((public.is_tenant_member(tenant_id) OR (owner_id = auth.uid())));


--
-- Name: addon_products; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.addon_products ENABLE ROW LEVEL SECURITY;

--
-- Name: addon_products addon_products_admin_all; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY addon_products_admin_all ON public.addon_products TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.saas_admins
  WHERE (saas_admins.user_id = auth.uid())))) WITH CHECK ((EXISTS ( SELECT 1
   FROM public.saas_admins
  WHERE (saas_admins.user_id = auth.uid()))));


--
-- Name: addon_products addon_products_select_authenticated; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY addon_products_select_authenticated ON public.addon_products FOR SELECT TO authenticated USING (((deleted_at IS NULL) AND (is_active = true) AND (is_visible = true)));


--
-- Name: addon_transactions; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.addon_transactions ENABLE ROW LEVEL SECURITY;

--
-- Name: addon_transactions addon_transactions_admin_insert; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY addon_transactions_admin_insert ON public.addon_transactions FOR INSERT TO authenticated WITH CHECK ((EXISTS ( SELECT 1
   FROM public.saas_admins
  WHERE (saas_admins.user_id = auth.uid()))));


--
-- Name: addon_transactions addon_transactions_admin_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY addon_transactions_admin_select ON public.addon_transactions FOR SELECT TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.saas_admins
  WHERE (saas_admins.user_id = auth.uid()))));


--
-- Name: addon_transactions addon_transactions_select_own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY addon_transactions_select_own ON public.addon_transactions FOR SELECT TO authenticated USING ((public.is_tenant_member(tenant_id) OR (owner_id = auth.uid())));


--
-- Name: agenda_bloqueios; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.agenda_bloqueios ENABLE ROW LEVEL SECURITY;

--
-- Name: agenda_configuracoes; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.agenda_configuracoes ENABLE ROW LEVEL SECURITY;

--
-- Name: agenda_configuracoes agenda_configuracoes_clinic_read; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agenda_configuracoes_clinic_read ON public.agenda_configuracoes FOR SELECT USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.view'::text)));


--
-- Name: agenda_configuracoes agenda_configuracoes_clinic_write; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agenda_configuracoes_clinic_write ON public.agenda_configuracoes USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.edit'::text))) WITH CHECK ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.edit'::text)));


--
-- Name: agenda_configuracoes agenda_configuracoes_owner; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agenda_configuracoes_owner ON public.agenda_configuracoes USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: agenda_eventos; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.agenda_eventos ENABLE ROW LEVEL SECURITY;

--
-- Name: agenda_eventos agenda_eventos_delete; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agenda_eventos_delete ON public.agenda_eventos FOR DELETE USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.delete'::text)));


--
-- Name: agenda_eventos agenda_eventos_insert; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agenda_eventos_insert ON public.agenda_eventos FOR INSERT WITH CHECK ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.create'::text)));


--
-- Name: agenda_eventos agenda_eventos_owner_all; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agenda_eventos_owner_all ON public.agenda_eventos TO authenticated USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: agenda_eventos agenda_eventos_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agenda_eventos_select ON public.agenda_eventos FOR SELECT USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.view'::text)));


--
-- Name: agenda_eventos agenda_eventos_update; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agenda_eventos_update ON public.agenda_eventos FOR UPDATE USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.edit'::text))) WITH CHECK ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.edit'::text)));


--
-- Name: agenda_excecoes; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.agenda_excecoes ENABLE ROW LEVEL SECURITY;

--
-- Name: agenda_excecoes agenda_excecoes_owner; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agenda_excecoes_owner ON public.agenda_excecoes USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: agenda_excecoes agenda_excecoes_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agenda_excecoes_select ON public.agenda_excecoes FOR SELECT USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.view'::text)));


--
-- Name: agenda_excecoes agenda_excecoes_write; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agenda_excecoes_write ON public.agenda_excecoes USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.edit'::text))) WITH CHECK ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.edit'::text)));


--
-- Name: agenda_online_slots; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.agenda_online_slots ENABLE ROW LEVEL SECURITY;

--
-- Name: agenda_online_slots agenda_online_slots_owner; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agenda_online_slots_owner ON public.agenda_online_slots USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: agenda_online_slots agenda_online_slots_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agenda_online_slots_select ON public.agenda_online_slots FOR SELECT USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.view'::text)));


--
-- Name: agenda_online_slots agenda_online_slots_write; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agenda_online_slots_write ON public.agenda_online_slots USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.edit'::text))) WITH CHECK ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.edit'::text)));


--
-- Name: agenda_regras_semanais; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.agenda_regras_semanais ENABLE ROW LEVEL SECURITY;

--
-- Name: agenda_regras_semanais agenda_regras_semanais_owner; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agenda_regras_semanais_owner ON public.agenda_regras_semanais USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: agenda_regras_semanais agenda_regras_semanais_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agenda_regras_semanais_select ON public.agenda_regras_semanais FOR SELECT USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.view'::text)));


--
-- Name: agenda_regras_semanais agenda_regras_semanais_write; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agenda_regras_semanais_write ON public.agenda_regras_semanais USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.edit'::text))) WITH CHECK ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.edit'::text)));


--
-- Name: agenda_slots_bloqueados_semanais; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.agenda_slots_bloqueados_semanais ENABLE ROW LEVEL SECURITY;

--
-- Name: agenda_slots_bloqueados_semanais agenda_slots_bloqueados_semanais_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agenda_slots_bloqueados_semanais_select ON public.agenda_slots_bloqueados_semanais FOR SELECT USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.view'::text)));


--
-- Name: agenda_slots_bloqueados_semanais agenda_slots_bloqueados_semanais_write; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agenda_slots_bloqueados_semanais_write ON public.agenda_slots_bloqueados_semanais USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.edit'::text))) WITH CHECK ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.edit'::text)));


--
-- Name: agenda_slots_regras; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.agenda_slots_regras ENABLE ROW LEVEL SECURITY;

--
-- Name: agenda_slots_regras agenda_slots_regras_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agenda_slots_regras_select ON public.agenda_slots_regras FOR SELECT USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.view'::text)));


--
-- Name: agenda_slots_regras agenda_slots_regras_write; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agenda_slots_regras_write ON public.agenda_slots_regras USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.edit'::text))) WITH CHECK ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.edit'::text)));


--
-- Name: agendador_configuracoes agendador_cfg_public_read; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agendador_cfg_public_read ON public.agendador_configuracoes FOR SELECT TO anon USING (((ativo = true) AND (link_slug IS NOT NULL)));


--
-- Name: agendador_configuracoes agendador_cfg_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agendador_cfg_select ON public.agendador_configuracoes FOR SELECT USING ((auth.uid() = owner_id));


--
-- Name: agendador_configuracoes agendador_cfg_write; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agendador_cfg_write ON public.agendador_configuracoes USING ((auth.uid() = owner_id)) WITH CHECK ((auth.uid() = owner_id));


--
-- Name: agendador_configuracoes; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.agendador_configuracoes ENABLE ROW LEVEL SECURITY;

--
-- Name: agendador_solicitacoes agendador_sol_owner_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agendador_sol_owner_select ON public.agendador_solicitacoes FOR SELECT USING ((auth.uid() = owner_id));


--
-- Name: agendador_solicitacoes agendador_sol_owner_write; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agendador_sol_owner_write ON public.agendador_solicitacoes USING ((auth.uid() = owner_id)) WITH CHECK ((auth.uid() = owner_id));


--
-- Name: agendador_solicitacoes agendador_sol_patient_read; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agendador_sol_patient_read ON public.agendador_solicitacoes FOR SELECT TO authenticated USING (((auth.uid() = user_id) OR (auth.uid() = owner_id)));


--
-- Name: agendador_solicitacoes agendador_sol_public_insert; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY agendador_sol_public_insert ON public.agendador_solicitacoes FOR INSERT TO anon WITH CHECK (true);


--
-- Name: agendador_solicitacoes; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.agendador_solicitacoes ENABLE ROW LEVEL SECURITY;

--
-- Name: billing_contracts; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.billing_contracts ENABLE ROW LEVEL SECURITY;

--
-- Name: billing_contracts billing_contracts: owner full access; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "billing_contracts: owner full access" ON public.billing_contracts USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: agenda_bloqueios bloqueios_delete; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY bloqueios_delete ON public.agenda_bloqueios FOR DELETE TO authenticated USING ((owner_id = auth.uid()));


--
-- Name: agenda_bloqueios bloqueios_insert; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY bloqueios_insert ON public.agenda_bloqueios FOR INSERT TO authenticated WITH CHECK ((owner_id = auth.uid()));


--
-- Name: agenda_bloqueios bloqueios_select_clinic; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY bloqueios_select_clinic ON public.agenda_bloqueios FOR SELECT TO authenticated USING ((tenant_id IN ( SELECT tenant_members.tenant_id
   FROM public.tenant_members
  WHERE ((tenant_members.user_id = auth.uid()) AND (tenant_members.role = ANY (ARRAY['admin'::text, 'clinic_admin'::text, 'tenant_admin'::text, 'secretary'::text]))))));


--
-- Name: agenda_bloqueios bloqueios_select_own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY bloqueios_select_own ON public.agenda_bloqueios FOR SELECT TO authenticated USING ((owner_id = auth.uid()));


--
-- Name: agenda_bloqueios bloqueios_update; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY bloqueios_update ON public.agenda_bloqueios FOR UPDATE TO authenticated USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: saas_docs clinic_admin_read_all_docs; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY clinic_admin_read_all_docs ON public.saas_docs FOR SELECT TO authenticated USING (((ativo = true) AND (EXISTS ( SELECT 1
   FROM public.profiles
  WHERE ((profiles.id = auth.uid()) AND (profiles.role = ANY (ARRAY['clinic_admin'::text, 'tenant_admin'::text])))))));


--
-- Name: commitment_services; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.commitment_services ENABLE ROW LEVEL SECURITY;

--
-- Name: commitment_services commitment_services: owner full access; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "commitment_services: owner full access" ON public.commitment_services USING ((EXISTS ( SELECT 1
   FROM public.services s
  WHERE ((s.id = commitment_services.service_id) AND (s.owner_id = auth.uid()))))) WITH CHECK ((EXISTS ( SELECT 1
   FROM public.services s
  WHERE ((s.id = commitment_services.service_id) AND (s.owner_id = auth.uid())))));


--
-- Name: commitment_time_logs; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.commitment_time_logs ENABLE ROW LEVEL SECURITY;

--
-- Name: company_profiles; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.company_profiles ENABLE ROW LEVEL SECURITY;

--
-- Name: company_profiles company_profiles_delete; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY company_profiles_delete ON public.company_profiles FOR DELETE USING ((tenant_id = auth.uid()));


--
-- Name: company_profiles company_profiles_insert; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY company_profiles_insert ON public.company_profiles FOR INSERT WITH CHECK ((tenant_id = auth.uid()));


--
-- Name: company_profiles company_profiles_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY company_profiles_select ON public.company_profiles FOR SELECT USING ((tenant_id = auth.uid()));


--
-- Name: company_profiles company_profiles_update; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY company_profiles_update ON public.company_profiles FOR UPDATE USING ((tenant_id = auth.uid()));


--
-- Name: commitment_time_logs ctl_delete_for_active_member; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY ctl_delete_for_active_member ON public.commitment_time_logs FOR DELETE TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.tenant_members tm
  WHERE ((tm.tenant_id = commitment_time_logs.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text)))));


--
-- Name: commitment_time_logs ctl_insert_for_active_member; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY ctl_insert_for_active_member ON public.commitment_time_logs FOR INSERT TO authenticated WITH CHECK ((EXISTS ( SELECT 1
   FROM public.tenant_members tm
  WHERE ((tm.tenant_id = commitment_time_logs.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text)))));


--
-- Name: commitment_time_logs ctl_select_for_active_member; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY ctl_select_for_active_member ON public.commitment_time_logs FOR SELECT TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.tenant_members tm
  WHERE ((tm.tenant_id = commitment_time_logs.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text)))));


--
-- Name: commitment_time_logs ctl_update_for_active_member; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY ctl_update_for_active_member ON public.commitment_time_logs FOR UPDATE TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.tenant_members tm
  WHERE ((tm.tenant_id = commitment_time_logs.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text))))) WITH CHECK ((EXISTS ( SELECT 1
   FROM public.tenant_members tm
  WHERE ((tm.tenant_id = commitment_time_logs.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text)))));


--
-- Name: determined_commitments dc_delete_custom_for_active_member; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY dc_delete_custom_for_active_member ON public.determined_commitments FOR DELETE TO authenticated USING (((is_native = false) AND (EXISTS ( SELECT 1
   FROM public.tenant_members tm
  WHERE ((tm.tenant_id = determined_commitments.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text))))));


--
-- Name: determined_commitments dc_insert_for_active_member; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY dc_insert_for_active_member ON public.determined_commitments FOR INSERT TO authenticated WITH CHECK ((EXISTS ( SELECT 1
   FROM public.tenant_members tm
  WHERE ((tm.tenant_id = determined_commitments.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text)))));


--
-- Name: determined_commitments dc_select_for_active_member; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY dc_select_for_active_member ON public.determined_commitments FOR SELECT TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.tenant_members tm
  WHERE ((tm.tenant_id = determined_commitments.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text)))));


--
-- Name: determined_commitments dc_update_for_active_member; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY dc_update_for_active_member ON public.determined_commitments FOR UPDATE TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.tenant_members tm
  WHERE ((tm.tenant_id = determined_commitments.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text))))) WITH CHECK ((EXISTS ( SELECT 1
   FROM public.tenant_members tm
  WHERE ((tm.tenant_id = determined_commitments.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text)))));


--
-- Name: determined_commitment_fields dcf_delete_for_active_member; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY dcf_delete_for_active_member ON public.determined_commitment_fields FOR DELETE TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.tenant_members tm
  WHERE ((tm.tenant_id = determined_commitment_fields.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text)))));


--
-- Name: determined_commitment_fields dcf_insert_for_active_member; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY dcf_insert_for_active_member ON public.determined_commitment_fields FOR INSERT TO authenticated WITH CHECK ((EXISTS ( SELECT 1
   FROM public.tenant_members tm
  WHERE ((tm.tenant_id = determined_commitment_fields.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text)))));


--
-- Name: determined_commitment_fields dcf_select_for_active_member; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY dcf_select_for_active_member ON public.determined_commitment_fields FOR SELECT TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.tenant_members tm
  WHERE ((tm.tenant_id = determined_commitment_fields.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text)))));


--
-- Name: determined_commitment_fields dcf_update_for_active_member; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY dcf_update_for_active_member ON public.determined_commitment_fields FOR UPDATE TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.tenant_members tm
  WHERE ((tm.tenant_id = determined_commitment_fields.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text))))) WITH CHECK ((EXISTS ( SELECT 1
   FROM public.tenant_members tm
  WHERE ((tm.tenant_id = determined_commitment_fields.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text)))));


--
-- Name: agenda_bloqueios delete own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "delete own" ON public.agenda_bloqueios FOR DELETE USING ((owner_id = auth.uid()));


--
-- Name: determined_commitment_fields; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.determined_commitment_fields ENABLE ROW LEVEL SECURITY;

--
-- Name: determined_commitments; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.determined_commitments ENABLE ROW LEVEL SECURITY;

--
-- Name: dev_user_credentials dev_creds_select_saas_admin; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY dev_creds_select_saas_admin ON public.dev_user_credentials FOR SELECT TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.profiles p
  WHERE ((p.id = auth.uid()) AND (p.role = 'saas_admin'::text)))));


--
-- Name: dev_user_credentials dev_creds_write_saas_admin; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY dev_creds_write_saas_admin ON public.dev_user_credentials TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.profiles p
  WHERE ((p.id = auth.uid()) AND (p.role = 'saas_admin'::text))))) WITH CHECK ((EXISTS ( SELECT 1
   FROM public.profiles p
  WHERE ((p.id = auth.uid()) AND (p.role = 'saas_admin'::text)))));


--
-- Name: dev_user_credentials; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.dev_user_credentials ENABLE ROW LEVEL SECURITY;

--
-- Name: email_layout_config; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.email_layout_config ENABLE ROW LEVEL SECURITY;

--
-- Name: email_templates_global; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.email_templates_global ENABLE ROW LEVEL SECURITY;

--
-- Name: email_templates_tenant; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.email_templates_tenant ENABLE ROW LEVEL SECURITY;

--
-- Name: entitlements_invalidation ent_inv_select_own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY ent_inv_select_own ON public.entitlements_invalidation FOR SELECT USING (((owner_id = auth.uid()) OR public.is_saas_admin()));


--
-- Name: entitlements_invalidation ent_inv_update_saas; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY ent_inv_update_saas ON public.entitlements_invalidation FOR UPDATE USING (public.is_saas_admin()) WITH CHECK (public.is_saas_admin());


--
-- Name: entitlements_invalidation ent_inv_write_saas; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY ent_inv_write_saas ON public.entitlements_invalidation FOR INSERT WITH CHECK (public.is_saas_admin());


--
-- Name: entitlements_invalidation; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.entitlements_invalidation ENABLE ROW LEVEL SECURITY;

--
-- Name: saas_faq faq_admin_write; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY faq_admin_write ON public.saas_faq TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.profiles
  WHERE ((profiles.id = auth.uid()) AND (profiles.role = ANY (ARRAY['saas_admin'::text, 'tenant_admin'::text, 'clinic_admin'::text]))))));


--
-- Name: saas_faq faq_auth_read; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY faq_auth_read ON public.saas_faq FOR SELECT TO authenticated USING ((ativo = true));


--
-- Name: saas_faq_itens faq_itens_admin_write; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY faq_itens_admin_write ON public.saas_faq_itens TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.profiles
  WHERE ((profiles.id = auth.uid()) AND (profiles.role = ANY (ARRAY['saas_admin'::text, 'tenant_admin'::text, 'clinic_admin'::text]))))));


--
-- Name: saas_faq_itens faq_itens_auth_read; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY faq_itens_auth_read ON public.saas_faq_itens FOR SELECT TO authenticated USING (((ativo = true) AND (EXISTS ( SELECT 1
   FROM public.saas_docs d
  WHERE ((d.id = saas_faq_itens.doc_id) AND (d.ativo = true))))));


--
-- Name: saas_faq faq_public_read; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY faq_public_read ON public.saas_faq FOR SELECT USING (((publico = true) AND (ativo = true)));


--
-- Name: features; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.features ENABLE ROW LEVEL SECURITY;

--
-- Name: features features_read_authenticated; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY features_read_authenticated ON public.features FOR SELECT TO authenticated USING (true);


--
-- Name: features features_write_saas_admin; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY features_write_saas_admin ON public.features TO authenticated USING (public.is_saas_admin()) WITH CHECK (public.is_saas_admin());


--
-- Name: feriados; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.feriados ENABLE ROW LEVEL SECURITY;

--
-- Name: feriados feriados_delete; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY feriados_delete ON public.feriados FOR DELETE USING ((owner_id = auth.uid()));


--
-- Name: feriados feriados_global_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY feriados_global_select ON public.feriados FOR SELECT USING ((tenant_id IS NULL));


--
-- Name: feriados feriados_insert; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY feriados_insert ON public.feriados FOR INSERT WITH CHECK ((tenant_id IN ( SELECT tenant_members.tenant_id
   FROM public.tenant_members
  WHERE (tenant_members.user_id = auth.uid()))));


--
-- Name: feriados feriados_saas_delete; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY feriados_saas_delete ON public.feriados FOR DELETE USING ((EXISTS ( SELECT 1
   FROM public.saas_admins
  WHERE (saas_admins.user_id = auth.uid()))));


--
-- Name: feriados feriados_saas_insert; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY feriados_saas_insert ON public.feriados FOR INSERT WITH CHECK ((EXISTS ( SELECT 1
   FROM public.saas_admins
  WHERE (saas_admins.user_id = auth.uid()))));


--
-- Name: feriados feriados_saas_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY feriados_saas_select ON public.feriados FOR SELECT USING ((EXISTS ( SELECT 1
   FROM public.saas_admins
  WHERE (saas_admins.user_id = auth.uid()))));


--
-- Name: feriados feriados_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY feriados_select ON public.feriados FOR SELECT USING ((tenant_id IN ( SELECT tenant_members.tenant_id
   FROM public.tenant_members
  WHERE (tenant_members.user_id = auth.uid()))));


--
-- Name: financial_categories; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.financial_categories ENABLE ROW LEVEL SECURITY;

--
-- Name: financial_categories financial_categories_self; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY financial_categories_self ON public.financial_categories USING ((auth.uid() = user_id)) WITH CHECK ((auth.uid() = user_id));


--
-- Name: financial_exceptions; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.financial_exceptions ENABLE ROW LEVEL SECURITY;

--
-- Name: financial_exceptions financial_exceptions: owner full access; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "financial_exceptions: owner full access" ON public.financial_exceptions USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: financial_exceptions financial_exceptions: tenant members read clinic rules; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "financial_exceptions: tenant members read clinic rules" ON public.financial_exceptions FOR SELECT USING (((owner_id IS NULL) AND (EXISTS ( SELECT 1
   FROM public.owner_users ou
  WHERE ((ou.owner_id = financial_exceptions.tenant_id) AND (ou.user_id = auth.uid()))))));


--
-- Name: financial_records; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.financial_records ENABLE ROW LEVEL SECURITY;

--
-- Name: financial_records financial_records_self; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY financial_records_self ON public.financial_records USING ((auth.uid() = owner_id)) WITH CHECK ((auth.uid() = owner_id));


--
-- Name: financial_records financial_records_tenant_admin; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY financial_records_tenant_admin ON public.financial_records FOR SELECT USING (((tenant_id IS NOT NULL) AND public.is_tenant_admin(tenant_id)));


--
-- Name: financial_records financial_records_tenant_member_read; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY financial_records_tenant_member_read ON public.financial_records FOR SELECT USING (((tenant_id IS NOT NULL) AND (EXISTS ( SELECT 1
   FROM public.tenant_members tm
  WHERE ((tm.tenant_id = financial_records.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text))))));


--
-- Name: email_templates_global global templates readable by authenticated; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "global templates readable by authenticated" ON public.email_templates_global FOR SELECT USING ((auth.role() = 'authenticated'::text));


--
-- Name: global_notices; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.global_notices ENABLE ROW LEVEL SECURITY;

--
-- Name: global_notices global_notices_saas_all; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY global_notices_saas_all ON public.global_notices TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.saas_admins
  WHERE (saas_admins.user_id = auth.uid()))));


--
-- Name: global_notices global_notices_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY global_notices_select ON public.global_notices FOR SELECT TO authenticated USING ((is_active = true));


--
-- Name: agenda_bloqueios insert own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "insert own" ON public.agenda_bloqueios FOR INSERT WITH CHECK ((owner_id = auth.uid()));


--
-- Name: insurance_plan_services; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.insurance_plan_services ENABLE ROW LEVEL SECURITY;

--
-- Name: insurance_plan_services insurance_plan_services_owner; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY insurance_plan_services_owner ON public.insurance_plan_services USING ((EXISTS ( SELECT 1
   FROM public.insurance_plans ip
  WHERE ((ip.id = insurance_plan_services.insurance_plan_id) AND (ip.owner_id = auth.uid()))))) WITH CHECK ((EXISTS ( SELECT 1
   FROM public.insurance_plans ip
  WHERE ((ip.id = insurance_plan_services.insurance_plan_id) AND (ip.owner_id = auth.uid())))));


--
-- Name: insurance_plans; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.insurance_plans ENABLE ROW LEVEL SECURITY;

--
-- Name: insurance_plans insurance_plans: owner full access; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "insurance_plans: owner full access" ON public.insurance_plans USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: login_carousel_slides; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.login_carousel_slides ENABLE ROW LEVEL SECURITY;

--
-- Name: module_features; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.module_features ENABLE ROW LEVEL SECURITY;

--
-- Name: module_features module_features_read_authenticated; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY module_features_read_authenticated ON public.module_features FOR SELECT TO authenticated USING (true);


--
-- Name: module_features module_features_write_saas_admin; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY module_features_write_saas_admin ON public.module_features TO authenticated USING (public.is_saas_admin()) WITH CHECK (public.is_saas_admin());


--
-- Name: modules; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.modules ENABLE ROW LEVEL SECURITY;

--
-- Name: modules modules_read_authenticated; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY modules_read_authenticated ON public.modules FOR SELECT TO authenticated USING (true);


--
-- Name: modules modules_write_saas_admin; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY modules_write_saas_admin ON public.modules TO authenticated USING (public.is_saas_admin()) WITH CHECK (public.is_saas_admin());


--
-- Name: notice_dismissals; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.notice_dismissals ENABLE ROW LEVEL SECURITY;

--
-- Name: notice_dismissals notice_dismissals_own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY notice_dismissals_own ON public.notice_dismissals TO authenticated USING ((user_id = auth.uid())) WITH CHECK ((user_id = auth.uid()));


--
-- Name: notification_logs notif_logs_owner; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY notif_logs_owner ON public.notification_logs FOR SELECT USING ((owner_id = auth.uid()));


--
-- Name: notification_preferences notif_prefs_owner; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY notif_prefs_owner ON public.notification_preferences USING (((owner_id = auth.uid()) AND (deleted_at IS NULL))) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: notification_queue notif_queue_owner; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY notif_queue_owner ON public.notification_queue FOR SELECT USING ((owner_id = auth.uid()));


--
-- Name: notification_schedules notif_schedules_owner; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY notif_schedules_owner ON public.notification_schedules USING (((owner_id = auth.uid()) AND (deleted_at IS NULL))) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: notification_templates notif_templates_admin_all; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY notif_templates_admin_all ON public.notification_templates TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.saas_admins
  WHERE (saas_admins.user_id = auth.uid())))) WITH CHECK ((EXISTS ( SELECT 1
   FROM public.saas_admins
  WHERE (saas_admins.user_id = auth.uid()))));


--
-- Name: notification_templates notif_templates_read_global; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY notif_templates_read_global ON public.notification_templates FOR SELECT TO authenticated USING (((deleted_at IS NULL) AND (((tenant_id IS NULL) AND (is_default = true)) OR (owner_id = auth.uid()) OR public.is_tenant_member(tenant_id))));


--
-- Name: notification_templates notif_templates_write_owner; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY notif_templates_write_owner ON public.notification_templates TO authenticated USING (((owner_id = auth.uid()) OR public.is_tenant_member(tenant_id))) WITH CHECK (((owner_id = auth.uid()) OR public.is_tenant_member(tenant_id)));


--
-- Name: notification_channels; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.notification_channels ENABLE ROW LEVEL SECURITY;

--
-- Name: notification_channels notification_channels_owner; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY notification_channels_owner ON public.notification_channels USING (((owner_id = auth.uid()) AND (deleted_at IS NULL))) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: notification_logs; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.notification_logs ENABLE ROW LEVEL SECURITY;

--
-- Name: notification_preferences; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.notification_preferences ENABLE ROW LEVEL SECURITY;

--
-- Name: notification_queue; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.notification_queue ENABLE ROW LEVEL SECURITY;

--
-- Name: notification_schedules; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.notification_schedules ENABLE ROW LEVEL SECURITY;

--
-- Name: notification_templates; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.notification_templates ENABLE ROW LEVEL SECURITY;

--
-- Name: notifications; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.notifications ENABLE ROW LEVEL SECURITY;

--
-- Name: notifications owner only; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "owner only" ON public.notifications USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: owner_users; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.owner_users ENABLE ROW LEVEL SECURITY;

--
-- Name: owner_users owner_users: user can read own links; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "owner_users: user can read own links" ON public.owner_users FOR SELECT TO authenticated USING ((user_id = auth.uid()));


--
-- Name: patient_discounts; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.patient_discounts ENABLE ROW LEVEL SECURITY;

--
-- Name: patient_discounts patient_discounts: owner full access; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "patient_discounts: owner full access" ON public.patient_discounts USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: patient_group_patient; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.patient_group_patient ENABLE ROW LEVEL SECURITY;

--
-- Name: patient_group_patient patient_group_patient_owner_all; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patient_group_patient_owner_all ON public.patient_group_patient TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.patients p
  WHERE ((p.id = patient_group_patient.patient_id) AND (p.owner_id = auth.uid()))))) WITH CHECK ((EXISTS ( SELECT 1
   FROM public.patients p
  WHERE ((p.id = patient_group_patient.patient_id) AND (p.owner_id = auth.uid())))));


--
-- Name: patient_group_patient patient_group_patient_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patient_group_patient_select ON public.patient_group_patient FOR SELECT USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.view'::text)));


--
-- Name: patient_group_patient patient_group_patient_write; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patient_group_patient_write ON public.patient_group_patient USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.edit'::text))) WITH CHECK ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.edit'::text)));


--
-- Name: patient_groups; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.patient_groups ENABLE ROW LEVEL SECURITY;

--
-- Name: patient_groups patient_groups_owner_all; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patient_groups_owner_all ON public.patient_groups TO authenticated USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: patient_groups patient_groups_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patient_groups_select ON public.patient_groups FOR SELECT USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.view'::text)));


--
-- Name: patient_groups patient_groups_write; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patient_groups_write ON public.patient_groups USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.edit'::text))) WITH CHECK ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.edit'::text)));


--
-- Name: patient_intake_requests; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.patient_intake_requests ENABLE ROW LEVEL SECURITY;

--
-- Name: patient_intake_requests patient_intake_requests_owner_all; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patient_intake_requests_owner_all ON public.patient_intake_requests TO authenticated USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: patient_intake_requests patient_intake_requests_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patient_intake_requests_select ON public.patient_intake_requests FOR SELECT USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.view'::text)));


--
-- Name: patient_intake_requests patient_intake_requests_write; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patient_intake_requests_write ON public.patient_intake_requests USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.edit'::text))) WITH CHECK ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.edit'::text)));


--
-- Name: patient_invites; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.patient_invites ENABLE ROW LEVEL SECURITY;

--
-- Name: patient_invites patient_invites_owner_all; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patient_invites_owner_all ON public.patient_invites TO authenticated USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: patient_invites patient_invites_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patient_invites_select ON public.patient_invites FOR SELECT USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.view'::text)));


--
-- Name: patient_invites patient_invites_write; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patient_invites_write ON public.patient_invites USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.edit'::text))) WITH CHECK ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.edit'::text)));


--
-- Name: patient_patient_tag; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.patient_patient_tag ENABLE ROW LEVEL SECURITY;

--
-- Name: patient_patient_tag patient_patient_tag_owner_all; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patient_patient_tag_owner_all ON public.patient_patient_tag TO authenticated USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: patient_patient_tag patient_patient_tag_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patient_patient_tag_select ON public.patient_patient_tag FOR SELECT USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.view'::text)));


--
-- Name: patient_patient_tag patient_patient_tag_write; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patient_patient_tag_write ON public.patient_patient_tag USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.edit'::text))) WITH CHECK ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.edit'::text)));


--
-- Name: patient_tags; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.patient_tags ENABLE ROW LEVEL SECURITY;

--
-- Name: patient_tags patient_tags_owner_all; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patient_tags_owner_all ON public.patient_tags TO authenticated USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: patient_tags patient_tags_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patient_tags_select ON public.patient_tags FOR SELECT USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.view'::text)));


--
-- Name: patient_tags patient_tags_write; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patient_tags_write ON public.patient_tags USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.edit'::text))) WITH CHECK ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.edit'::text)));


--
-- Name: patients; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.patients ENABLE ROW LEVEL SECURITY;

--
-- Name: patients patients_delete; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patients_delete ON public.patients FOR DELETE USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.delete'::text)));


--
-- Name: patients patients_insert; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patients_insert ON public.patients FOR INSERT WITH CHECK ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.create'::text)));


--
-- Name: patients patients_owner_all; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patients_owner_all ON public.patients TO authenticated USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: patients patients_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patients_select ON public.patients FOR SELECT USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.view'::text)));


--
-- Name: patients patients_update; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY patients_update ON public.patients FOR UPDATE USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.edit'::text))) WITH CHECK ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'patients.edit'::text)));


--
-- Name: payment_settings; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.payment_settings ENABLE ROW LEVEL SECURITY;

--
-- Name: payment_settings payment_settings: owner full access; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "payment_settings: owner full access" ON public.payment_settings USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: plan_features; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.plan_features ENABLE ROW LEVEL SECURITY;

--
-- Name: plan_features plan_features_read_authenticated; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY plan_features_read_authenticated ON public.plan_features FOR SELECT TO authenticated USING (true);


--
-- Name: plan_features plan_features_write_saas_admin; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY plan_features_write_saas_admin ON public.plan_features TO authenticated USING (public.is_saas_admin()) WITH CHECK (public.is_saas_admin());


--
-- Name: plans; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.plans ENABLE ROW LEVEL SECURITY;

--
-- Name: plans plans_read_authenticated; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY plans_read_authenticated ON public.plans FOR SELECT TO authenticated USING (true);


--
-- Name: plans plans_write_saas_admin; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY plans_write_saas_admin ON public.plans TO authenticated USING (public.is_saas_admin()) WITH CHECK (public.is_saas_admin());


--
-- Name: professional_pricing; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.professional_pricing ENABLE ROW LEVEL SECURITY;

--
-- Name: professional_pricing professional_pricing: owner full access; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "professional_pricing: owner full access" ON public.professional_pricing USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: profiles; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.profiles ENABLE ROW LEVEL SECURITY;

--
-- Name: profiles profiles_insert_own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY profiles_insert_own ON public.profiles FOR INSERT WITH CHECK ((id = auth.uid()));


--
-- Name: profiles profiles_read_saas_admin; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY profiles_read_saas_admin ON public.profiles FOR SELECT USING (public.is_saas_admin());


--
-- Name: profiles profiles_select_own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY profiles_select_own ON public.profiles FOR SELECT USING ((id = auth.uid()));


--
-- Name: profiles profiles_update_own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY profiles_update_own ON public.profiles FOR UPDATE USING ((id = auth.uid())) WITH CHECK ((id = auth.uid()));


--
-- Name: login_carousel_slides public_read; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY public_read ON public.login_carousel_slides FOR SELECT USING ((ativo = true));


--
-- Name: features read features (auth); Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "read features (auth)" ON public.features FOR SELECT TO authenticated USING (true);


--
-- Name: plan_features read plan_features (auth); Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "read plan_features (auth)" ON public.plan_features FOR SELECT TO authenticated USING (true);


--
-- Name: plans read plans (auth); Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "read plans (auth)" ON public.plans FOR SELECT TO authenticated USING (true);


--
-- Name: recurrence_exceptions; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.recurrence_exceptions ENABLE ROW LEVEL SECURITY;

--
-- Name: recurrence_exceptions recurrence_exceptions_tenant; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY recurrence_exceptions_tenant ON public.recurrence_exceptions TO authenticated USING ((tenant_id IN ( SELECT tenant_members.tenant_id
   FROM public.tenant_members
  WHERE (tenant_members.user_id = auth.uid())))) WITH CHECK ((tenant_id IN ( SELECT tenant_members.tenant_id
   FROM public.tenant_members
  WHERE (tenant_members.user_id = auth.uid()))));


--
-- Name: recurrence_rule_services; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.recurrence_rule_services ENABLE ROW LEVEL SECURITY;

--
-- Name: recurrence_rule_services recurrence_rule_services: clinic read; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "recurrence_rule_services: clinic read" ON public.recurrence_rule_services FOR SELECT USING ((EXISTS ( SELECT 1
   FROM public.recurrence_rules r
  WHERE ((r.id = recurrence_rule_services.rule_id) AND public.is_clinic_tenant(r.tenant_id) AND public.is_tenant_member(r.tenant_id) AND public.tenant_has_feature(r.tenant_id, 'agenda.view'::text)))));


--
-- Name: recurrence_rule_services recurrence_rule_services: clinic write; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "recurrence_rule_services: clinic write" ON public.recurrence_rule_services USING ((EXISTS ( SELECT 1
   FROM public.recurrence_rules r
  WHERE ((r.id = recurrence_rule_services.rule_id) AND public.is_clinic_tenant(r.tenant_id) AND public.is_tenant_member(r.tenant_id) AND public.tenant_has_feature(r.tenant_id, 'agenda.edit'::text))))) WITH CHECK ((EXISTS ( SELECT 1
   FROM public.recurrence_rules r
  WHERE ((r.id = recurrence_rule_services.rule_id) AND public.is_clinic_tenant(r.tenant_id) AND public.is_tenant_member(r.tenant_id) AND public.tenant_has_feature(r.tenant_id, 'agenda.edit'::text)))));


--
-- Name: recurrence_rule_services recurrence_rule_services: owner full access; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "recurrence_rule_services: owner full access" ON public.recurrence_rule_services TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.recurrence_rules r
  WHERE ((r.id = recurrence_rule_services.rule_id) AND (r.owner_id = auth.uid()))))) WITH CHECK ((EXISTS ( SELECT 1
   FROM public.recurrence_rules r
  WHERE ((r.id = recurrence_rule_services.rule_id) AND (r.owner_id = auth.uid())))));


--
-- Name: recurrence_rules; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.recurrence_rules ENABLE ROW LEVEL SECURITY;

--
-- Name: recurrence_rules recurrence_rules_clinic_read; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY recurrence_rules_clinic_read ON public.recurrence_rules FOR SELECT USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.view'::text)));


--
-- Name: recurrence_rules recurrence_rules_clinic_write; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY recurrence_rules_clinic_write ON public.recurrence_rules USING ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.edit'::text))) WITH CHECK ((public.is_clinic_tenant(tenant_id) AND public.is_tenant_member(tenant_id) AND public.tenant_has_feature(tenant_id, 'agenda.edit'::text)));


--
-- Name: recurrence_rules recurrence_rules_owner; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY recurrence_rules_owner ON public.recurrence_rules TO authenticated USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: subscription_intents_legacy saas_admin can read subscription_intents; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "saas_admin can read subscription_intents" ON public.subscription_intents_legacy FOR SELECT TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.saas_admins a
  WHERE (a.user_id = auth.uid()))));


--
-- Name: subscription_intents_legacy saas_admin can update subscription_intents; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "saas_admin can update subscription_intents" ON public.subscription_intents_legacy FOR UPDATE TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.saas_admins a
  WHERE (a.user_id = auth.uid())))) WITH CHECK ((EXISTS ( SELECT 1
   FROM public.saas_admins a
  WHERE (a.user_id = auth.uid()))));


--
-- Name: login_carousel_slides saas_admin_full; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY saas_admin_full ON public.login_carousel_slides USING ((EXISTS ( SELECT 1
   FROM public.profiles
  WHERE ((profiles.id = auth.uid()) AND (profiles.role = 'saas_admin'::text)))));


--
-- Name: saas_docs saas_admin_full_access; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY saas_admin_full_access ON public.saas_docs TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.saas_admins
  WHERE (saas_admins.user_id = auth.uid())))) WITH CHECK ((EXISTS ( SELECT 1
   FROM public.saas_admins
  WHERE (saas_admins.user_id = auth.uid()))));


--
-- Name: saas_admins; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.saas_admins ENABLE ROW LEVEL SECURITY;

--
-- Name: saas_admins saas_admins_select_self; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY saas_admins_select_self ON public.saas_admins FOR SELECT TO authenticated USING ((user_id = auth.uid()));


--
-- Name: saas_doc_votos; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.saas_doc_votos ENABLE ROW LEVEL SECURITY;

--
-- Name: saas_docs; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.saas_docs ENABLE ROW LEVEL SECURITY;

--
-- Name: saas_faq; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.saas_faq ENABLE ROW LEVEL SECURITY;

--
-- Name: saas_faq_itens; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.saas_faq_itens ENABLE ROW LEVEL SECURITY;

--
-- Name: agenda_bloqueios select own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "select own" ON public.agenda_bloqueios FOR SELECT USING ((owner_id = auth.uid()));


--
-- Name: services; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.services ENABLE ROW LEVEL SECURITY;

--
-- Name: services services: owner full access; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "services: owner full access" ON public.services USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));


--
-- Name: subscription_events; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.subscription_events ENABLE ROW LEVEL SECURITY;

--
-- Name: subscription_events subscription_events_read_saas; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY subscription_events_read_saas ON public.subscription_events FOR SELECT USING (public.is_saas_admin());


--
-- Name: subscription_events subscription_events_write_saas; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY subscription_events_write_saas ON public.subscription_events FOR INSERT WITH CHECK (public.is_saas_admin());


--
-- Name: subscription_intents_legacy subscription_intents_insert_own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY subscription_intents_insert_own ON public.subscription_intents_legacy FOR INSERT TO authenticated WITH CHECK ((user_id = auth.uid()));


--
-- Name: subscription_intents_legacy; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.subscription_intents_legacy ENABLE ROW LEVEL SECURITY;

--
-- Name: subscription_intents_legacy subscription_intents_select_own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY subscription_intents_select_own ON public.subscription_intents_legacy FOR SELECT TO authenticated USING ((user_id = auth.uid()));


--
-- Name: subscriptions; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.subscriptions ENABLE ROW LEVEL SECURITY;

--
-- Name: subscriptions subscriptions read own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "subscriptions read own" ON public.subscriptions FOR SELECT TO authenticated USING ((user_id = auth.uid()));


--
-- Name: subscriptions subscriptions: read if linked owner_users; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "subscriptions: read if linked owner_users" ON public.subscriptions FOR SELECT TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.owner_users ou
  WHERE ((ou.owner_id = subscriptions.user_id) AND (ou.user_id = auth.uid())))));


--
-- Name: subscriptions subscriptions_insert_own_personal; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY subscriptions_insert_own_personal ON public.subscriptions FOR INSERT TO authenticated WITH CHECK (((user_id = auth.uid()) AND (tenant_id IS NULL)));


--
-- Name: subscriptions subscriptions_no_direct_update; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY subscriptions_no_direct_update ON public.subscriptions FOR UPDATE TO authenticated USING (false) WITH CHECK (false);


--
-- Name: subscriptions subscriptions_read_own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY subscriptions_read_own ON public.subscriptions FOR SELECT TO authenticated USING (((user_id = auth.uid()) OR public.is_saas_admin()));


--
-- Name: subscriptions subscriptions_select_for_tenant_members; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY subscriptions_select_for_tenant_members ON public.subscriptions FOR SELECT TO authenticated USING (((tenant_id IS NOT NULL) AND (EXISTS ( SELECT 1
   FROM public.tenant_members tm
  WHERE ((tm.tenant_id = subscriptions.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text))))));


--
-- Name: subscriptions subscriptions_select_own_personal; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY subscriptions_select_own_personal ON public.subscriptions FOR SELECT TO authenticated USING (((user_id = auth.uid()) AND (tenant_id IS NULL)));


--
-- Name: subscriptions subscriptions_update_only_saas_admin; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY subscriptions_update_only_saas_admin ON public.subscriptions FOR UPDATE TO authenticated USING (public.is_saas_admin()) WITH CHECK (public.is_saas_admin());


--
-- Name: support_sessions; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.support_sessions ENABLE ROW LEVEL SECURITY;

--
-- Name: support_sessions support_sessions_saas_delete; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY support_sessions_saas_delete ON public.support_sessions FOR DELETE USING (((auth.uid() = admin_id) AND (EXISTS ( SELECT 1
   FROM public.profiles
  WHERE ((profiles.id = auth.uid()) AND (profiles.role = 'saas_admin'::text))))));


--
-- Name: support_sessions support_sessions_saas_insert; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY support_sessions_saas_insert ON public.support_sessions FOR INSERT WITH CHECK (((auth.uid() = admin_id) AND (EXISTS ( SELECT 1
   FROM public.profiles
  WHERE ((profiles.id = auth.uid()) AND (profiles.role = 'saas_admin'::text))))));


--
-- Name: support_sessions support_sessions_saas_select; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY support_sessions_saas_select ON public.support_sessions FOR SELECT USING (((auth.uid() = admin_id) AND (EXISTS ( SELECT 1
   FROM public.profiles
  WHERE ((profiles.id = auth.uid()) AND (profiles.role = 'saas_admin'::text))))));


--
-- Name: email_templates_tenant tenant manages own overrides; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "tenant manages own overrides" ON public.email_templates_tenant USING ((tenant_id = auth.uid())) WITH CHECK ((tenant_id = auth.uid()));


--
-- Name: email_layout_config tenant owns email layout config; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "tenant owns email layout config" ON public.email_layout_config USING ((tenant_id = auth.uid())) WITH CHECK ((tenant_id = auth.uid()));


--
-- Name: tenant_members; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.tenant_members ENABLE ROW LEVEL SECURITY;

--
-- Name: tenant_members tenant_members_write_saas; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY tenant_members_write_saas ON public.tenant_members TO authenticated USING (public.is_saas_admin()) WITH CHECK (public.is_saas_admin());


--
-- Name: tenant_modules; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.tenant_modules ENABLE ROW LEVEL SECURITY;

--
-- Name: tenant_modules tenant_modules_read_own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY tenant_modules_read_own ON public.tenant_modules FOR SELECT TO authenticated USING (((owner_id = auth.uid()) OR public.is_saas_admin()));


--
-- Name: tenant_modules tenant_modules_write_saas; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY tenant_modules_write_saas ON public.tenant_modules TO authenticated USING (public.is_saas_admin()) WITH CHECK (public.is_saas_admin());


--
-- Name: tenants; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.tenants ENABLE ROW LEVEL SECURITY;

--
-- Name: tenants tenants_read_members; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY tenants_read_members ON public.tenants FOR SELECT TO authenticated USING ((public.is_saas_admin() OR (EXISTS ( SELECT 1
   FROM public.tenant_members tm
  WHERE ((tm.tenant_id = tenants.id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text))))));


--
-- Name: tenants tenants_write_saas; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY tenants_write_saas ON public.tenants TO authenticated USING (public.is_saas_admin()) WITH CHECK (public.is_saas_admin());


--
-- Name: therapist_payout_records; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.therapist_payout_records ENABLE ROW LEVEL SECURITY;

--
-- Name: therapist_payout_records therapist_payout_records_self; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY therapist_payout_records_self ON public.therapist_payout_records USING ((EXISTS ( SELECT 1
   FROM public.therapist_payouts tp
  WHERE ((tp.id = therapist_payout_records.payout_id) AND (tp.owner_id = auth.uid()))))) WITH CHECK ((EXISTS ( SELECT 1
   FROM public.therapist_payouts tp
  WHERE ((tp.id = therapist_payout_records.payout_id) AND (tp.owner_id = auth.uid())))));


--
-- Name: therapist_payout_records therapist_payout_records_tenant_admin; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY therapist_payout_records_tenant_admin ON public.therapist_payout_records FOR SELECT USING ((EXISTS ( SELECT 1
   FROM public.therapist_payouts tp
  WHERE ((tp.id = therapist_payout_records.payout_id) AND public.is_tenant_admin(tp.tenant_id)))));


--
-- Name: therapist_payouts; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.therapist_payouts ENABLE ROW LEVEL SECURITY;

--
-- Name: therapist_payouts therapist_payouts_self; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY therapist_payouts_self ON public.therapist_payouts USING ((auth.uid() = owner_id)) WITH CHECK ((auth.uid() = owner_id));


--
-- Name: therapist_payouts therapist_payouts_tenant_admin; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY therapist_payouts_tenant_admin ON public.therapist_payouts FOR SELECT USING (((tenant_id IS NOT NULL) AND public.is_tenant_admin(tenant_id)));


--
-- Name: tenant_members tm_select_admin_all_members; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY tm_select_admin_all_members ON public.tenant_members FOR SELECT TO authenticated USING (public.is_tenant_admin(tenant_id));


--
-- Name: tenant_members tm_select_own_membership; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY tm_select_own_membership ON public.tenant_members FOR SELECT TO authenticated USING ((user_id = auth.uid()));


--
-- Name: agenda_bloqueios update own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "update own" ON public.agenda_bloqueios FOR UPDATE USING ((owner_id = auth.uid()));


--
-- Name: user_settings; Type: ROW SECURITY; Schema: public; Owner: supabase_admin
--

ALTER TABLE public.user_settings ENABLE ROW LEVEL SECURITY;

--
-- Name: user_settings user_settings_insert_own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY user_settings_insert_own ON public.user_settings FOR INSERT WITH CHECK ((user_id = auth.uid()));


--
-- Name: user_settings user_settings_select_own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY user_settings_select_own ON public.user_settings FOR SELECT USING ((user_id = auth.uid()));


--
-- Name: user_settings user_settings_update_own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY user_settings_update_own ON public.user_settings FOR UPDATE USING ((user_id = auth.uid())) WITH CHECK ((user_id = auth.uid()));


--
-- Name: saas_docs users_read_usuario_docs; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY users_read_usuario_docs ON public.saas_docs FOR SELECT TO authenticated USING (((ativo = true) AND (tipo_acesso = 'usuario'::text)));


--
-- Name: saas_doc_votos votos_select_own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY votos_select_own ON public.saas_doc_votos FOR SELECT TO authenticated USING ((user_id = auth.uid()));


--
-- Name: saas_doc_votos votos_upsert_own; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY votos_upsert_own ON public.saas_doc_votos TO authenticated USING ((user_id = auth.uid())) WITH CHECK ((user_id = auth.uid()));


--
-- Name: messages; Type: ROW SECURITY; Schema: realtime; Owner: supabase_realtime_admin
--

ALTER TABLE realtime.messages ENABLE ROW LEVEL SECURITY;

--
-- Name: objects agendador_storage_owner_delete; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY agendador_storage_owner_delete ON storage.objects FOR DELETE TO authenticated USING (((bucket_id = 'agendador'::text) AND ((storage.foldername(name))[1] = (auth.uid())::text)));


--
-- Name: objects agendador_storage_owner_insert; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY agendador_storage_owner_insert ON storage.objects FOR INSERT TO authenticated WITH CHECK (((bucket_id = 'agendador'::text) AND ((storage.foldername(name))[1] = (auth.uid())::text)));


--
-- Name: objects agendador_storage_owner_update; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY agendador_storage_owner_update ON storage.objects FOR UPDATE TO authenticated USING (((bucket_id = 'agendador'::text) AND ((storage.foldername(name))[1] = (auth.uid())::text)));


--
-- Name: objects agendador_storage_public_read; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY agendador_storage_public_read ON storage.objects FOR SELECT USING ((bucket_id = 'agendador'::text));


--
-- Name: objects avatars authenticated upload; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "avatars authenticated upload" ON storage.objects FOR INSERT WITH CHECK (((bucket_id = 'avatars'::text) AND (auth.role() = 'authenticated'::text) AND ((storage.foldername(name))[1] = (auth.uid())::text)));


--
-- Name: objects avatars owner delete; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "avatars owner delete" ON storage.objects FOR DELETE USING (((bucket_id = 'avatars'::text) AND ((storage.foldername(name))[1] = (auth.uid())::text)));


--
-- Name: objects avatars owner update; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "avatars owner update" ON storage.objects FOR UPDATE USING (((bucket_id = 'avatars'::text) AND ((storage.foldername(name))[1] = (auth.uid())::text)));


--
-- Name: objects avatars public read; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "avatars public read" ON storage.objects FOR SELECT USING ((bucket_id = 'avatars'::text));


--
-- Name: objects avatars_delete_own; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY avatars_delete_own ON storage.objects FOR DELETE TO authenticated USING (((bucket_id = 'avatars'::text) AND (name ~~ ((auth.uid())::text || '/%'::text))));


--
-- Name: objects avatars_delete_own_folder; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY avatars_delete_own_folder ON storage.objects FOR DELETE USING (((bucket_id = 'avatars'::text) AND (auth.role() = 'authenticated'::text) AND (name ~~ (('owners/'::text || auth.uid()) || '/%'::text))));


--
-- Name: objects avatars_insert_own; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY avatars_insert_own ON storage.objects FOR INSERT TO authenticated WITH CHECK (((bucket_id = 'avatars'::text) AND (name ~~ ((auth.uid())::text || '/%'::text))));


--
-- Name: objects avatars_insert_own_folder; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY avatars_insert_own_folder ON storage.objects FOR INSERT WITH CHECK (((bucket_id = 'avatars'::text) AND (auth.role() = 'authenticated'::text) AND (name ~~ (('owners/'::text || auth.uid()) || '/%'::text))));


--
-- Name: objects avatars_read; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY avatars_read ON storage.objects FOR SELECT USING ((bucket_id = 'avatars'::text));


--
-- Name: objects avatars_select_own; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY avatars_select_own ON storage.objects FOR SELECT TO authenticated USING (((bucket_id = 'avatars'::text) AND (name ~~ ((auth.uid())::text || '/%'::text))));


--
-- Name: objects avatars_update_own; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY avatars_update_own ON storage.objects FOR UPDATE TO authenticated USING (((bucket_id = 'avatars'::text) AND (name ~~ ((auth.uid())::text || '/%'::text)))) WITH CHECK (((bucket_id = 'avatars'::text) AND (name ~~ ((auth.uid())::text || '/%'::text))));


--
-- Name: objects avatars_update_own_folder; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY avatars_update_own_folder ON storage.objects FOR UPDATE USING (((bucket_id = 'avatars'::text) AND (auth.role() = 'authenticated'::text) AND (name ~~ (('owners/'::text || auth.uid()) || '/%'::text)))) WITH CHECK (((bucket_id = 'avatars'::text) AND (auth.role() = 'authenticated'::text) AND (name ~~ (('owners/'::text || auth.uid()) || '/%'::text))));


--
-- Name: buckets; Type: ROW SECURITY; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE storage.buckets ENABLE ROW LEVEL SECURITY;

--
-- Name: buckets_analytics; Type: ROW SECURITY; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE storage.buckets_analytics ENABLE ROW LEVEL SECURITY;

--
-- Name: buckets_vectors; Type: ROW SECURITY; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE storage.buckets_vectors ENABLE ROW LEVEL SECURITY;

--
-- Name: iceberg_namespaces; Type: ROW SECURITY; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE storage.iceberg_namespaces ENABLE ROW LEVEL SECURITY;

--
-- Name: iceberg_tables; Type: ROW SECURITY; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE storage.iceberg_tables ENABLE ROW LEVEL SECURITY;

--
-- Name: objects intake_read_anon; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY intake_read_anon ON storage.objects FOR SELECT TO anon USING (((bucket_id = 'avatars'::text) AND (name ~~ 'intakes/%'::text)));


--
-- Name: objects intake_read_public; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY intake_read_public ON storage.objects FOR SELECT USING (((bucket_id = 'avatars'::text) AND (name ~~ 'intakes/%'::text)));


--
-- Name: objects intake_upload_anon; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY intake_upload_anon ON storage.objects FOR INSERT TO anon WITH CHECK (((bucket_id = 'avatars'::text) AND (name ~~ 'intakes/%'::text)));


--
-- Name: objects intake_upload_public; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY intake_upload_public ON storage.objects FOR INSERT WITH CHECK (((bucket_id = 'avatars'::text) AND (name ~~ 'intakes/%'::text)));


--
-- Name: migrations; Type: ROW SECURITY; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE storage.migrations ENABLE ROW LEVEL SECURITY;

--
-- Name: objects; Type: ROW SECURITY; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE storage.objects ENABLE ROW LEVEL SECURITY;

--
-- Name: objects public_read; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY public_read ON storage.objects FOR SELECT USING ((bucket_id = 'saas-docs'::text));


--
-- Name: s3_multipart_uploads; Type: ROW SECURITY; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE storage.s3_multipart_uploads ENABLE ROW LEVEL SECURITY;

--
-- Name: s3_multipart_uploads_parts; Type: ROW SECURITY; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE storage.s3_multipart_uploads_parts ENABLE ROW LEVEL SECURITY;

--
-- Name: objects saas_admin_delete; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY saas_admin_delete ON storage.objects FOR DELETE TO authenticated USING (((bucket_id = 'saas-docs'::text) AND (EXISTS ( SELECT 1
   FROM public.saas_admins
  WHERE (saas_admins.user_id = auth.uid())))));


--
-- Name: objects saas_admin_upload; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY saas_admin_upload ON storage.objects FOR INSERT TO authenticated WITH CHECK (((bucket_id = 'saas-docs'::text) AND (EXISTS ( SELECT 1
   FROM public.saas_admins
  WHERE (saas_admins.user_id = auth.uid())))));


--
-- Name: vector_indexes; Type: ROW SECURITY; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE storage.vector_indexes ENABLE ROW LEVEL SECURITY;

--
-- Name: supabase_realtime; Type: PUBLICATION; Schema: -; Owner: postgres
--

CREATE PUBLICATION supabase_realtime WITH (publish = 'insert, update, delete, truncate');


ALTER PUBLICATION supabase_realtime OWNER TO postgres;

--
-- Name: supabase_realtime_messages_publication; Type: PUBLICATION; Schema: -; Owner: supabase_admin
--

CREATE PUBLICATION supabase_realtime_messages_publication WITH (publish = 'insert, update, delete, truncate');


ALTER PUBLICATION supabase_realtime_messages_publication OWNER TO supabase_admin;

--
-- Name: supabase_realtime notifications; Type: PUBLICATION TABLE; Schema: public; Owner: postgres
--

ALTER PUBLICATION supabase_realtime ADD TABLE ONLY public.notifications;


--
-- Name: supabase_realtime_messages_publication messages; Type: PUBLICATION TABLE; Schema: realtime; Owner: supabase_admin
--

ALTER PUBLICATION supabase_realtime_messages_publication ADD TABLE ONLY realtime.messages;


--
-- Name: SCHEMA auth; Type: ACL; Schema: -; Owner: supabase_admin
--

