-- Allow any authenticated user to insert their own comments
CREATE POLICY "Authenticated users can insert own entity_comments"
ON public.entity_comments
FOR INSERT
TO authenticated
WITH CHECK (auth.uid() = user_id);

-- Allow any authenticated user to insert their own votes
CREATE POLICY "Authenticated users can insert own entity_votes"
ON public.entity_votes
FOR INSERT
TO authenticated
WITH CHECK (auth.uid() = user_id);

-- Allow any authenticated user to update their own votes
CREATE POLICY "Authenticated users can update own entity_votes"
ON public.entity_votes
FOR UPDATE
TO authenticated
USING (auth.uid() = user_id)
WITH CHECK (auth.uid() = user_id);

-- Allow any authenticated user to delete their own votes
CREATE POLICY "Authenticated users can delete own entity_votes"
ON public.entity_votes
FOR DELETE
TO authenticated
USING (auth.uid() = user_id);

-- Allow any authenticated user to delete their own comments
CREATE POLICY "Authenticated users can delete own entity_comments"
ON public.entity_comments
FOR DELETE
TO authenticated
USING (auth.uid() = user_id);

-- Enable realtime for both tables
ALTER PUBLICATION supabase_realtime ADD TABLE public.entity_votes;
ALTER PUBLICATION supabase_realtime ADD TABLE public.entity_comments;