Files
Sauci/apps/supabase/migrations/20231227000009_chat_updates.sql
T
2025-12-27 19:10:11 +00:00

22 lines
617 B
SQL

-- Add read_at column
ALTER TABLE public.messages ADD COLUMN IF NOT EXISTS read_at TIMESTAMPTZ;
-- Allow users to update read_at for messages where they are NOT the sender
CREATE POLICY "Users can mark messages as read"
ON public.messages
FOR UPDATE
USING (
auth.uid() != user_id AND
EXISTS (
SELECT 1 FROM public.matches m
WHERE m.id = messages.match_id
AND m.couple_id IN (
SELECT couple_id FROM public.profiles
WHERE id = auth.uid()
)
)
)
WITH CHECK (
auth.uid() != user_id
);