- Changed Supabase URL and anon key for the connection. - Added a cache buster file for page caching management. - Integrated ChatMessages component into AcompanhamentoPaciente and MensagensMedico pages for improved messaging interface. - Created new MensagensPaciente page for patient messaging. - Updated PainelMedico to include messaging functionality with patients. - Enhanced message service to support conversation retrieval and message sending. - Added a test HTML file for Supabase connection verification and message table interaction.
39 lines
1.4 KiB
SQL
39 lines
1.4 KiB
SQL
-- Script simplificado para criar tabela messages
|
|
-- SEM Row Level Security (RLS) para autenticação customizada
|
|
|
|
-- 1. Remover tabela antiga se existir
|
|
DROP TABLE IF EXISTS public.messages CASCADE;
|
|
|
|
-- 2. Criar tabela de mensagens
|
|
CREATE TABLE public.messages (
|
|
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
|
|
sender_id TEXT NOT NULL,
|
|
receiver_id TEXT NOT NULL,
|
|
content TEXT NOT NULL,
|
|
read BOOLEAN DEFAULT false,
|
|
created_at TIMESTAMPTZ DEFAULT now(),
|
|
updated_at TIMESTAMPTZ DEFAULT now()
|
|
);
|
|
|
|
-- 3. Criar índices para performance
|
|
CREATE INDEX idx_messages_sender ON public.messages(sender_id);
|
|
CREATE INDEX idx_messages_receiver ON public.messages(receiver_id);
|
|
CREATE INDEX idx_messages_created_at ON public.messages(created_at DESC);
|
|
CREATE INDEX idx_messages_conversation ON public.messages(sender_id, receiver_id, created_at DESC);
|
|
|
|
-- 4. DESABILITAR RLS (importante para autenticação customizada)
|
|
ALTER TABLE public.messages DISABLE ROW LEVEL SECURITY;
|
|
|
|
-- 5. Garantir permissões para anon (chave pública)
|
|
GRANT ALL ON public.messages TO anon;
|
|
GRANT ALL ON public.messages TO authenticated;
|
|
GRANT ALL ON public.messages TO service_role;
|
|
|
|
-- 6. Garantir que sequences podem ser usadas
|
|
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO anon;
|
|
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO authenticated;
|
|
|
|
-- 7. Verificar
|
|
SELECT 'Tabela messages criada com sucesso!' as status;
|
|
SELECT COUNT(*) as total_mensagens FROM public.messages;
|