-- Fix RLS policy for recognition_logs table
-- Run this in your Supabase SQL Editor

-- 1. Enable RLS (just in case)
ALTER TABLE public.recognition_logs ENABLE ROW LEVEL SECURITY;

-- 2. Drop existing policies to cleanly recreate them
DROP POLICY IF EXISTS "Anyone can log recognitions" ON public.recognition_logs;
DROP POLICY IF EXISTS "Enable insert for all users" ON public.recognition_logs;
DROP POLICY IF EXISTS "Enable read for all users" ON public.recognition_logs;

-- 3. Create permissive policies for both INSERT and SELECT
-- Allow the API (anon/service_role) to insert logs
CREATE POLICY "Enable insert for all users"
  ON public.recognition_logs FOR INSERT
  WITH CHECK (true);

-- Allow reading logs (if needed for dashboard)
CREATE POLICY "Enable read for all users"
  ON public.recognition_logs FOR SELECT
  USING (true);

-- 4. Verify policies
SELECT tablename, policyname, cmd, diff_key 
FROM pg_policies 
WHERE tablename = 'recognition_logs';
