db: migration session_default_notes_field + schema regenerado
Migration 20260511000001 adiciona campo 'notes' (Observacao, textarea, sort_order=30) como campo extra default no commitment determinado 'Sessao'. Antes Sessao era a unica excecao entre os nativos — Leitura/Supervisao/ Aula/Analise ja tinham. Padroniza pra que a Observacao da sessao siga o mesmo mecanismo de extra_fields dos outros, e o frontend remova a textarea hardcoded do AgendaEventDialog (proximo commit). Backfill: insere 'notes' em TODOS os commitments Sessao ja existentes (idempotente). Forward-fix: substitui a funcao seed_determined_commitments incluindo o bloco de Sessao + 'notes' pra novos tenants. Schema regenerado via db.cjs schema-export pra refletir o estado pos- migration. agenciapsi-db-dashboard.html regenerado pelo generate-dashboard.cjs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
-- RLS Policies
|
||||
-- Gerado automaticamente em 2026-04-21T23:16:34.967Z
|
||||
-- Enable RLS: 131 tabelas
|
||||
-- Policies: 344
|
||||
-- Gerado automaticamente em 2026-05-11T16:53:50.939Z
|
||||
-- Enable RLS: 137 tabelas
|
||||
-- Policies: 357
|
||||
|
||||
-- Enable RLS
|
||||
ALTER TABLE public.addon_credits ENABLE ROW LEVEL SECURITY;
|
||||
@@ -26,12 +26,17 @@ ALTER TABLE public.contact_email_types ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.contact_emails ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.contact_phones ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.contact_types ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.conversation_assignments ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.conversation_autoreply_log ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.conversation_autoreply_settings ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.conversation_bot_sessions ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.conversation_bots ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.conversation_messages ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.conversation_notes ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.conversation_optout_keywords ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.conversation_optouts ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.conversation_sla_breaches ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.conversation_sla_rules ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.conversation_tags ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.conversation_thread_tags ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.determined_commitment_fields ENABLE ROW LEVEL SECURITY;
|
||||
@@ -131,6 +136,7 @@ ALTER TABLE public.therapist_payout_records ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.therapist_payouts ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.twilio_subaccount_usage ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.user_settings ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.whatsapp_connection_incidents ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.whatsapp_credit_packages ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.whatsapp_credit_purchases ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.whatsapp_credits_balance ENABLE ROW LEVEL SECURITY;
|
||||
@@ -273,6 +279,12 @@ CREATE POLICY bloqueios_select_own ON public.agenda_bloqueios FOR SELECT TO auth
|
||||
|
||||
CREATE POLICY bloqueios_update ON public.agenda_bloqueios FOR UPDATE TO authenticated USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid()));
|
||||
|
||||
CREATE POLICY "bot_sessions: select membros" ON public.conversation_bot_sessions FOR SELECT TO authenticated USING ((public.is_saas_admin() OR (EXISTS ( SELECT 1
|
||||
FROM public.tenant_members tm
|
||||
WHERE ((tm.tenant_id = conversation_bot_sessions.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text))))));
|
||||
|
||||
CREATE POLICY "bot_sessions: write service_role" ON public.conversation_bot_sessions TO service_role USING (true) WITH CHECK (true);
|
||||
|
||||
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])))))));
|
||||
@@ -335,6 +347,32 @@ CREATE POLICY "contact_types: select" ON public.contact_types FOR SELECT TO auth
|
||||
FROM public.tenant_members tm
|
||||
WHERE ((tm.user_id = auth.uid()) AND (tm.tenant_id = contact_types.tenant_id) AND (tm.status = 'active'::text))))));
|
||||
|
||||
CREATE POLICY "conv_assign: insert tenant" ON public.conversation_assignments FOR INSERT TO authenticated WITH CHECK (((assigned_by = auth.uid()) AND (EXISTS ( SELECT 1
|
||||
FROM public.tenant_members tm
|
||||
WHERE ((tm.user_id = auth.uid()) AND (tm.tenant_id = conversation_assignments.tenant_id) AND (tm.status = 'active'::text)))) AND ((assigned_to IS NULL) OR (EXISTS ( SELECT 1
|
||||
FROM public.tenant_members tm2
|
||||
WHERE ((tm2.user_id = conversation_assignments.assigned_to) AND (tm2.tenant_id = conversation_assignments.tenant_id) AND (tm2.status = 'active'::text)))))));
|
||||
|
||||
CREATE POLICY "conv_assign: select tenant" ON public.conversation_assignments FOR SELECT TO authenticated USING ((public.is_saas_admin() OR (EXISTS ( SELECT 1
|
||||
FROM public.tenant_members tm
|
||||
WHERE ((tm.user_id = auth.uid()) AND (tm.tenant_id = conversation_assignments.tenant_id) AND (tm.status = 'active'::text))))));
|
||||
|
||||
CREATE POLICY "conv_assign: update tenant" ON public.conversation_assignments FOR UPDATE TO authenticated USING ((EXISTS ( SELECT 1
|
||||
FROM public.tenant_members tm
|
||||
WHERE ((tm.user_id = auth.uid()) AND (tm.tenant_id = conversation_assignments.tenant_id) AND (tm.status = 'active'::text))))) WITH CHECK (((assigned_by = auth.uid()) AND ((assigned_to IS NULL) OR (EXISTS ( SELECT 1
|
||||
FROM public.tenant_members tm2
|
||||
WHERE ((tm2.user_id = conversation_assignments.assigned_to) AND (tm2.tenant_id = conversation_assignments.tenant_id) AND (tm2.status = 'active'::text)))))));
|
||||
|
||||
CREATE POLICY "conv_bots: select membros" ON public.conversation_bots FOR SELECT TO authenticated USING ((public.is_saas_admin() OR (EXISTS ( SELECT 1
|
||||
FROM public.tenant_members tm
|
||||
WHERE ((tm.tenant_id = conversation_bots.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text))))));
|
||||
|
||||
CREATE POLICY "conv_bots: write admins" ON public.conversation_bots TO authenticated USING ((public.is_saas_admin() OR (EXISTS ( SELECT 1
|
||||
FROM public.tenant_members tm
|
||||
WHERE ((tm.tenant_id = conversation_bots.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.role = ANY (ARRAY['clinic_admin'::text, 'tenant_admin'::text])) AND (tm.status = 'active'::text)))))) WITH CHECK ((public.is_saas_admin() OR (EXISTS ( SELECT 1
|
||||
FROM public.tenant_members tm
|
||||
WHERE ((tm.tenant_id = conversation_bots.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.role = ANY (ARRAY['clinic_admin'::text, 'tenant_admin'::text])) AND (tm.status = 'active'::text))))));
|
||||
|
||||
CREATE POLICY "conv_msg: no direct delete" ON public.conversation_messages FOR DELETE TO authenticated USING (false);
|
||||
|
||||
CREATE POLICY "conv_msg: no direct insert" ON public.conversation_messages FOR INSERT TO authenticated WITH CHECK (false);
|
||||
@@ -677,9 +715,9 @@ CREATE POLICY notif_channels_insert ON public.notification_channels FOR INSERT T
|
||||
|
||||
CREATE POLICY notif_channels_modify ON public.notification_channels FOR UPDATE TO authenticated USING (((owner_id = auth.uid()) OR public.is_saas_admin())) WITH CHECK (((owner_id = auth.uid()) OR public.is_saas_admin()));
|
||||
|
||||
CREATE POLICY notif_channels_select ON public.notification_channels FOR SELECT TO authenticated USING (((deleted_at IS NULL) AND (public.is_saas_admin() OR (owner_id = auth.uid()) OR (tenant_id IN ( SELECT tm.tenant_id
|
||||
CREATE POLICY notif_channels_select ON public.notification_channels FOR SELECT USING ((public.is_saas_admin() OR (owner_id = auth.uid()) OR (tenant_id IN ( SELECT tm.tenant_id
|
||||
FROM public.tenant_members tm
|
||||
WHERE ((tm.user_id = auth.uid()) AND (tm.status = 'active'::text)))))));
|
||||
WHERE ((tm.user_id = auth.uid()) AND (tm.status = 'active'::text))))));
|
||||
|
||||
CREATE POLICY notif_logs_owner ON public.notification_logs FOR SELECT USING ((owner_id = auth.uid()));
|
||||
|
||||
@@ -933,6 +971,22 @@ CREATE POLICY "services: select" ON public.services FOR SELECT TO authenticated
|
||||
|
||||
CREATE POLICY "services: update" ON public.services FOR UPDATE TO authenticated USING (((owner_id = auth.uid()) OR public.is_saas_admin())) WITH CHECK (((owner_id = auth.uid()) OR public.is_saas_admin()));
|
||||
|
||||
CREATE POLICY "sla_breaches: select membros/admin" ON public.conversation_sla_breaches FOR SELECT TO authenticated USING ((public.is_saas_admin() OR (EXISTS ( SELECT 1
|
||||
FROM public.tenant_members tm
|
||||
WHERE ((tm.tenant_id = conversation_sla_breaches.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text))))));
|
||||
|
||||
CREATE POLICY "sla_breaches: write service_role" ON public.conversation_sla_breaches TO service_role USING (true) WITH CHECK (true);
|
||||
|
||||
CREATE POLICY "sla_rules: select membros/admin" ON public.conversation_sla_rules FOR SELECT TO authenticated USING ((public.is_saas_admin() OR (EXISTS ( SELECT 1
|
||||
FROM public.tenant_members tm
|
||||
WHERE ((tm.tenant_id = conversation_sla_rules.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text))))));
|
||||
|
||||
CREATE POLICY "sla_rules: write admins" ON public.conversation_sla_rules TO authenticated USING ((public.is_saas_admin() OR (EXISTS ( SELECT 1
|
||||
FROM public.tenant_members tm
|
||||
WHERE ((tm.tenant_id = conversation_sla_rules.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.role = ANY (ARRAY['clinic_admin'::text, 'tenant_admin'::text])) AND (tm.status = 'active'::text)))))) WITH CHECK ((public.is_saas_admin() OR (EXISTS ( SELECT 1
|
||||
FROM public.tenant_members tm
|
||||
WHERE ((tm.tenant_id = conversation_sla_rules.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.role = ANY (ARRAY['clinic_admin'::text, 'tenant_admin'::text])) AND (tm.status = 'active'::text))))));
|
||||
|
||||
CREATE POLICY srl_read_saas_admin ON public.submission_rate_limits FOR SELECT TO authenticated USING (public.is_saas_admin());
|
||||
|
||||
CREATE POLICY subscription_events_read_saas ON public.subscription_events FOR SELECT USING (public.is_saas_admin());
|
||||
@@ -1067,6 +1121,12 @@ CREATE POLICY "wa_credits_tx: select tenant" ON public.whatsapp_credits_transact
|
||||
FROM public.tenant_members tm
|
||||
WHERE ((tm.user_id = auth.uid()) AND (tm.tenant_id = whatsapp_credits_transactions.tenant_id) AND (tm.status = 'active'::text))))));
|
||||
|
||||
CREATE POLICY "wa_incidents: select membros/admin" ON public.whatsapp_connection_incidents FOR SELECT TO authenticated USING ((public.is_saas_admin() OR (EXISTS ( SELECT 1
|
||||
FROM public.tenant_members tm
|
||||
WHERE ((tm.tenant_id = whatsapp_connection_incidents.tenant_id) AND (tm.user_id = auth.uid()) AND (tm.status = 'active'::text))))));
|
||||
|
||||
CREATE POLICY "wa_incidents: write service_role" ON public.whatsapp_connection_incidents TO service_role USING (true) WITH CHECK (true);
|
||||
|
||||
CREATE POLICY "wa_packages: manage saas admin" ON public.whatsapp_credit_packages TO authenticated USING (public.is_saas_admin()) WITH CHECK (public.is_saas_admin());
|
||||
|
||||
CREATE POLICY "wa_packages: select active" ON public.whatsapp_credit_packages FOR SELECT TO authenticated USING (((is_active = true) OR public.is_saas_admin()));
|
||||
|
||||
Reference in New Issue
Block a user