-- Verify and fix event_lap_records RLS policies
-- This script is idempotent and safe to run multiple times

-- Drop ALL existing policies first
DROP POLICY IF EXISTS "Event lap records are viewable by everyone" ON event_lap_records;
DROP POLICY IF EXISTS "Authenticated users can insert event lap records" ON event_lap_records;
DROP POLICY IF EXISTS "Authenticated users can update event lap records" ON event_lap_records;
DROP POLICY IF EXISTS "Anyone can insert event lap records" ON event_lap_records;
DROP POLICY IF EXISTS "Anyone can update event lap records" ON event_lap_records;

-- Recreate policies with public access
CREATE POLICY "Event lap records are viewable by everyone"
  ON event_lap_records FOR SELECT
  USING (true);

CREATE POLICY "Anyone can insert event lap records"
  ON event_lap_records FOR INSERT
  WITH CHECK (true);

CREATE POLICY "Anyone can update event lap records"
  ON event_lap_records FOR UPDATE
  USING (true);

-- Verify policies are created
SELECT schemaname, tablename, policyname, permissive, roles, cmd, qual, with_check
FROM pg_policies
WHERE tablename = 'event_lap_records'
ORDER BY policyname;
