-- Add permissive INSERT policy for anon (idempotent).
DO $$
BEGIN
  IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name='task_activity_logs') THEN
    -- create policy only if it doesn't already exist
    IF NOT EXISTS (
      SELECT 1 FROM pg_policies WHERE tablename = 'task_activity_logs' AND policyname = 'allow_anon_insert'
    ) THEN
      EXECUTE 'CREATE POLICY allow_anon_insert ON public.task_activity_logs FOR INSERT TO anon WITH CHECK (true)';
    END IF;
  END IF;
END
$$;
