File size: 1,687 Bytes
1978ca7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
-- Complete RLS Policy Fix for All Tables
-- Run this in your Supabase SQL Editor

-- ============================================================
-- FIX 1: Allow INSERT to species table
-- ============================================================

-- Drop existing INSERT policies if any
DROP POLICY IF EXISTS "Allow service role to insert species" ON public.species;
DROP POLICY IF EXISTS "Allow inserts to species" ON public.species;
DROP POLICY IF EXISTS "Anyone can insert species" ON public.species;

-- Create new policy to allow INSERT operations
-- This allows the API (using anon key) to insert new species
CREATE POLICY "Allow authenticated inserts to species"
  ON public.species FOR INSERT
  WITH CHECK (true);

-- ============================================================
-- FIX 2: Allow INSERT to species_submissions table
-- ============================================================

-- Drop existing INSERT policies if any
DROP POLICY IF EXISTS "Allow inserts to submissions" ON public.species_submissions;

-- The schema already has this policy, but let's make sure it exists
-- CREATE POLICY "Anyone can submit new species"
--   ON public.species_submissions FOR INSERT
--   WITH CHECK (true);
-- (This should already exist from your schema)

-- ============================================================
-- Verify all policies
-- ============================================================

SELECT 
    schemaname, 
    tablename, 
    policyname, 
    permissive,
    cmd as operation,
    qual as using_expression,
    with_check
FROM pg_policies
WHERE tablename IN ('species', 'species_submissions', 'recognition_logs')
ORDER BY tablename, policyname;