carousel, agenda arquivados, agenda cor, agenda arquivados, grupos pacientes, pacientes arquivados - desativados, sessoes verificadas, ajuste notificações, Prontuario, Agenda Animation, Menu Profile, bagdes Profile, Offline
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
\restrict WhNBUHGPb7r3TzvGfUbgAGypOAZRhELU6FHGPvMhYkVWhF2Y5HPG9HrKQluVdLN
|
||||
\restrict exm15ajuo5LlVoZOAon82WdOxbqbyivLILLlrvWu0yn6dCEmYCyZgXRS28Q2h1h
|
||||
|
||||
-- Dumped from database version 17.6
|
||||
-- Dumped by pg_dump version 17.6
|
||||
@@ -2886,6 +2886,105 @@ $$;
|
||||
|
||||
ALTER FUNCTION public.my_tenants() OWNER TO supabase_admin;
|
||||
|
||||
--
|
||||
-- Name: notify_on_intake(); Type: FUNCTION; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.notify_on_intake() RETURNS trigger
|
||||
LANGUAGE plpgsql SECURITY DEFINER
|
||||
AS $$
|
||||
BEGIN
|
||||
IF NEW.status = 'new' THEN
|
||||
INSERT INTO public.notifications (
|
||||
owner_id,
|
||||
tenant_id,
|
||||
type,
|
||||
ref_id,
|
||||
ref_table,
|
||||
payload
|
||||
)
|
||||
VALUES (
|
||||
NEW.owner_id,
|
||||
NEW.tenant_id,
|
||||
'new_patient',
|
||||
NEW.id,
|
||||
'patient_intake_requests',
|
||||
jsonb_build_object(
|
||||
'title', 'Novo cadastro externo',
|
||||
'detail', COALESCE(NEW.nome_completo, 'Paciente'),
|
||||
'deeplink', '/therapist/patients/cadastro/recebidos',
|
||||
'avatar_initials', upper(left(COALESCE(NEW.nome_completo, '?'), 2))
|
||||
)
|
||||
);
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.notify_on_intake() OWNER TO supabase_admin;
|
||||
|
||||
--
|
||||
-- Name: notify_on_scheduling(); Type: FUNCTION; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.notify_on_scheduling() RETURNS trigger
|
||||
LANGUAGE plpgsql SECURITY DEFINER
|
||||
AS $$ BEGIN IF NEW.status = 'pendente' THEN
|
||||
INSERT INTO public.notifications ( owner_id, tenant_id, type, ref_id, ref_table, payload ) VALUES (
|
||||
NEW.owner_id, NEW.tenant_id,
|
||||
'new_scheduling', NEW.id, 'agendador_solicitacoes', jsonb_build_object( 'title', 'Nova solicitação de agendamento', 'detail', COALESCE(NEW.paciente_nome, 'Paciente') || ' ' || COALESCE(NEW.paciente_sobrenome, '') || ' — ' || COALESCE(NEW.tipo, ''), 'deeplink', '/therapist/agendamentos-recebidos', 'avatar_initials', upper(left(COALESCE(NEW.paciente_nome, '?'), 1) || left(COALESCE(NEW.paciente_sobrenome, ''), 1)) ) ); END IF; RETURN NEW; END; $$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.notify_on_scheduling() OWNER TO supabase_admin;
|
||||
|
||||
--
|
||||
-- Name: notify_on_session_status(); Type: FUNCTION; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.notify_on_session_status() RETURNS trigger
|
||||
LANGUAGE plpgsql SECURITY DEFINER
|
||||
AS $$
|
||||
DECLARE
|
||||
v_nome text;
|
||||
BEGIN
|
||||
IF NEW.status IN ('faltou', 'cancelado') AND OLD.status IS DISTINCT FROM NEW.status THEN
|
||||
-- tenta buscar nome do paciente
|
||||
SELECT nome_completo
|
||||
INTO v_nome
|
||||
FROM public.patients
|
||||
WHERE id = NEW.patient_id
|
||||
LIMIT 1;
|
||||
|
||||
INSERT INTO public.notifications (
|
||||
owner_id,
|
||||
tenant_id,
|
||||
type,
|
||||
ref_id,
|
||||
ref_table,
|
||||
payload
|
||||
)
|
||||
VALUES (
|
||||
NEW.owner_id,
|
||||
NEW.tenant_id,
|
||||
'session_status',
|
||||
NEW.id,
|
||||
'agenda_eventos',
|
||||
jsonb_build_object(
|
||||
'title', CASE WHEN NEW.status = 'faltou' THEN 'Paciente faltou' ELSE 'Sessão cancelada' END,
|
||||
'detail', COALESCE(v_nome, 'Paciente') || ' — ' || to_char(NEW.starts_at, 'DD/MM HH24:MI'),
|
||||
'deeplink', '/therapist/agenda',
|
||||
'avatar_initials', upper(left(COALESCE(v_nome, '?'), 2))
|
||||
)
|
||||
);
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.notify_on_session_status() OWNER TO supabase_admin;
|
||||
|
||||
--
|
||||
-- Name: on_new_user_seed_patient_groups(); Type: FUNCTION; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
@@ -7832,6 +7931,24 @@ CREATE TABLE public.insurance_plans (
|
||||
|
||||
ALTER TABLE public.insurance_plans OWNER TO supabase_admin;
|
||||
|
||||
--
|
||||
-- Name: login_carousel_slides; Type: TABLE; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
|
||||
CREATE TABLE public.login_carousel_slides (
|
||||
id uuid DEFAULT gen_random_uuid() NOT NULL,
|
||||
title text NOT NULL,
|
||||
body text NOT NULL,
|
||||
icon text DEFAULT 'pi-star'::text NOT NULL,
|
||||
ordem integer DEFAULT 0 NOT NULL,
|
||||
ativo boolean DEFAULT true NOT NULL,
|
||||
created_at timestamp with time zone DEFAULT now(),
|
||||
updated_at timestamp with time zone DEFAULT now()
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.login_carousel_slides OWNER TO supabase_admin;
|
||||
|
||||
--
|
||||
-- Name: module_features; Type: TABLE; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
@@ -7863,6 +7980,27 @@ CREATE TABLE public.modules (
|
||||
|
||||
ALTER TABLE public.modules OWNER TO supabase_admin;
|
||||
|
||||
--
|
||||
-- Name: notifications; Type: TABLE; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
|
||||
CREATE TABLE public.notifications (
|
||||
id uuid DEFAULT gen_random_uuid() NOT NULL,
|
||||
owner_id uuid NOT NULL,
|
||||
tenant_id uuid,
|
||||
type text NOT NULL,
|
||||
ref_id uuid,
|
||||
ref_table text,
|
||||
payload jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||||
read_at timestamp with time zone,
|
||||
archived boolean DEFAULT false NOT NULL,
|
||||
created_at timestamp with time zone DEFAULT now() NOT NULL,
|
||||
CONSTRAINT notifications_type_check CHECK ((type = ANY (ARRAY['new_scheduling'::text, 'new_patient'::text, 'recurrence_alert'::text, 'session_status'::text])))
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.notifications OWNER TO supabase_admin;
|
||||
|
||||
--
|
||||
-- Name: plan_features; Type: TABLE; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
@@ -10497,6 +10635,14 @@ ALTER TABLE ONLY public.insurance_plans
|
||||
ADD CONSTRAINT insurance_plans_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: login_carousel_slides login_carousel_slides_pkey; Type: CONSTRAINT; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.login_carousel_slides
|
||||
ADD CONSTRAINT login_carousel_slides_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: module_features module_features_pkey; Type: CONSTRAINT; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
@@ -10521,6 +10667,14 @@ ALTER TABLE ONLY public.modules
|
||||
ADD CONSTRAINT modules_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: notifications notifications_pkey; Type: CONSTRAINT; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.notifications
|
||||
ADD CONSTRAINT notifications_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: owner_users owner_users_pkey; Type: CONSTRAINT; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
@@ -12042,6 +12196,20 @@ CREATE INDEX ix_plan_public_bullets_plan ON public.plan_public_bullets USING btr
|
||||
CREATE INDEX ix_plan_public_sort ON public.plan_public USING btree (sort_order);
|
||||
|
||||
|
||||
--
|
||||
-- Name: notifications_owner_created; Type: INDEX; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
|
||||
CREATE INDEX notifications_owner_created ON public.notifications USING btree (owner_id, created_at DESC);
|
||||
|
||||
|
||||
--
|
||||
-- Name: notifications_owner_unread; Type: INDEX; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
|
||||
CREATE INDEX notifications_owner_unread ON public.notifications USING btree (owner_id, read_at) WHERE (read_at IS NULL);
|
||||
|
||||
|
||||
--
|
||||
-- Name: patient_discounts_owner_idx; Type: INDEX; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
@@ -13050,6 +13218,27 @@ CREATE TRIGGER trg_no_change_plan_target BEFORE UPDATE ON public.plans FOR EACH
|
||||
CREATE TRIGGER trg_no_delete_core_plans BEFORE DELETE ON public.plans FOR EACH ROW EXECUTE FUNCTION public.guard_no_delete_core_plans();
|
||||
|
||||
|
||||
--
|
||||
-- Name: patient_intake_requests trg_notify_on_intake; Type: TRIGGER; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
|
||||
CREATE TRIGGER trg_notify_on_intake AFTER INSERT ON public.patient_intake_requests FOR EACH ROW EXECUTE FUNCTION public.notify_on_intake();
|
||||
|
||||
|
||||
--
|
||||
-- Name: agendador_solicitacoes trg_notify_on_scheduling; Type: TRIGGER; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
|
||||
CREATE TRIGGER trg_notify_on_scheduling AFTER INSERT ON public.agendador_solicitacoes FOR EACH ROW EXECUTE FUNCTION public.notify_on_scheduling();
|
||||
|
||||
|
||||
--
|
||||
-- Name: agenda_eventos trg_notify_on_session_status; Type: TRIGGER; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
|
||||
CREATE TRIGGER trg_notify_on_session_status AFTER UPDATE OF status ON public.agenda_eventos FOR EACH ROW EXECUTE FUNCTION public.notify_on_session_status();
|
||||
|
||||
|
||||
--
|
||||
-- Name: tenant_members trg_patient_cannot_own_tenant; Type: TRIGGER; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
@@ -13643,6 +13832,14 @@ ALTER TABLE ONLY public.module_features
|
||||
ADD CONSTRAINT module_features_module_id_fkey FOREIGN KEY (module_id) REFERENCES public.modules(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: notifications notifications_owner_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.notifications
|
||||
ADD CONSTRAINT notifications_owner_id_fkey FOREIGN KEY (owner_id) REFERENCES auth.users(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: patient_discounts patient_discounts_owner_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
@@ -14960,6 +15157,12 @@ ALTER TABLE public.insurance_plans ENABLE ROW LEVEL SECURITY;
|
||||
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
|
||||
--
|
||||
@@ -15000,6 +15203,19 @@ CREATE POLICY modules_read_authenticated ON public.modules FOR SELECT TO authent
|
||||
CREATE POLICY modules_write_saas_admin ON public.modules TO authenticated USING (public.is_saas_admin()) WITH CHECK (public.is_saas_admin());
|
||||
|
||||
|
||||
--
|
||||
-- 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
|
||||
--
|
||||
@@ -15333,6 +15549,13 @@ CREATE POLICY profiles_select_own ON public.profiles FOR SELECT USING ((id = aut
|
||||
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
|
||||
--
|
||||
@@ -15455,6 +15678,15 @@ CREATE POLICY "saas_admin can update subscription_intents" ON public.subscriptio
|
||||
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
|
||||
--
|
||||
@@ -15998,6 +16230,29 @@ CREATE PUBLICATION supabase_realtime WITH (publish = 'insert, update, delete, tr
|
||||
|
||||
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
|
||||
--
|
||||
@@ -19290,6 +19545,36 @@ GRANT ALL ON FUNCTION public.my_tenants() TO authenticated;
|
||||
GRANT ALL ON FUNCTION public.my_tenants() TO service_role;
|
||||
|
||||
|
||||
--
|
||||
-- Name: FUNCTION notify_on_intake(); Type: ACL; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
|
||||
GRANT ALL ON FUNCTION public.notify_on_intake() TO postgres;
|
||||
GRANT ALL ON FUNCTION public.notify_on_intake() TO anon;
|
||||
GRANT ALL ON FUNCTION public.notify_on_intake() TO authenticated;
|
||||
GRANT ALL ON FUNCTION public.notify_on_intake() TO service_role;
|
||||
|
||||
|
||||
--
|
||||
-- Name: FUNCTION notify_on_scheduling(); Type: ACL; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
|
||||
GRANT ALL ON FUNCTION public.notify_on_scheduling() TO postgres;
|
||||
GRANT ALL ON FUNCTION public.notify_on_scheduling() TO anon;
|
||||
GRANT ALL ON FUNCTION public.notify_on_scheduling() TO authenticated;
|
||||
GRANT ALL ON FUNCTION public.notify_on_scheduling() TO service_role;
|
||||
|
||||
|
||||
--
|
||||
-- Name: FUNCTION notify_on_session_status(); Type: ACL; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
|
||||
GRANT ALL ON FUNCTION public.notify_on_session_status() TO postgres;
|
||||
GRANT ALL ON FUNCTION public.notify_on_session_status() TO anon;
|
||||
GRANT ALL ON FUNCTION public.notify_on_session_status() TO authenticated;
|
||||
GRANT ALL ON FUNCTION public.notify_on_session_status() TO service_role;
|
||||
|
||||
|
||||
--
|
||||
-- Name: FUNCTION oid_dist(oid, oid); Type: ACL; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
@@ -20773,6 +21058,16 @@ GRANT ALL ON TABLE public.insurance_plans TO authenticated;
|
||||
GRANT ALL ON TABLE public.insurance_plans TO service_role;
|
||||
|
||||
|
||||
--
|
||||
-- Name: TABLE login_carousel_slides; Type: ACL; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
|
||||
GRANT ALL ON TABLE public.login_carousel_slides TO postgres;
|
||||
GRANT ALL ON TABLE public.login_carousel_slides TO anon;
|
||||
GRANT ALL ON TABLE public.login_carousel_slides TO authenticated;
|
||||
GRANT ALL ON TABLE public.login_carousel_slides TO service_role;
|
||||
|
||||
|
||||
--
|
||||
-- Name: TABLE module_features; Type: ACL; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
@@ -20793,6 +21088,16 @@ GRANT ALL ON TABLE public.modules TO authenticated;
|
||||
GRANT ALL ON TABLE public.modules TO service_role;
|
||||
|
||||
|
||||
--
|
||||
-- Name: TABLE notifications; Type: ACL; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
|
||||
GRANT ALL ON TABLE public.notifications TO postgres;
|
||||
GRANT ALL ON TABLE public.notifications TO anon;
|
||||
GRANT ALL ON TABLE public.notifications TO authenticated;
|
||||
GRANT ALL ON TABLE public.notifications TO service_role;
|
||||
|
||||
|
||||
--
|
||||
-- Name: TABLE plan_features; Type: ACL; Schema: public; Owner: supabase_admin
|
||||
--
|
||||
@@ -21929,5 +22234,5 @@ ALTER EVENT TRIGGER pgrst_drop_watch OWNER TO supabase_admin;
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
\unrestrict WhNBUHGPb7r3TzvGfUbgAGypOAZRhELU6FHGPvMhYkVWhF2Y5HPG9HrKQluVdLN
|
||||
\unrestrict exm15ajuo5LlVoZOAon82WdOxbqbyivLILLlrvWu0yn6dCEmYCyZgXRS28Q2h1h
|
||||
|
||||
|
||||
Reference in New Issue
Block a user