mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-10-31 18:19:43 +00:00
22 lines
617 B
SQL
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
|
|
);
|