-- Fix event_lap_records RLS policies to allow public access
-- This is necessary because the live timing page tracks fastest laps for all users (authenticated or not)

-- Drop existing restrictive policies
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;

-- Create new public policies
-- Anyone can insert event lap records (the API validates the data)
CREATE POLICY "Anyone can insert event lap records"
  ON event_lap_records FOR INSERT
  WITH CHECK (true);

-- Anyone can update event lap records (the API ensures only faster times are recorded)
CREATE POLICY "Anyone can update event lap records"
  ON event_lap_records FOR UPDATE
  USING (true);

-- Keep the read policy as-is (already public)
-- CREATE POLICY "Event lap records are viewable by everyone"
--   ON event_lap_records FOR SELECT
--   USING (true);
