File size: 2,551 Bytes
be95560 | 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | -- Complete fix for species table INSERT issues
-- Run this in your Supabase SQL Editor
-- ============================================================
-- STEP 1: Check current RLS policies
-- ============================================================
SELECT
schemaname,
tablename,
policyname,
permissive,
cmd as operation,
qual as using_expression,
with_check
FROM pg_policies
WHERE tablename = 'species'
ORDER BY policyname;
-- ============================================================
-- STEP 2: Drop ALL existing policies on species table
-- ============================================================
DROP POLICY IF EXISTS "Species are viewable by everyone" ON public.species;
DROP POLICY IF EXISTS "Allow authenticated inserts to species" ON public.species;
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;
-- ============================================================
-- STEP 3: Create new policies
-- ============================================================
-- Allow everyone to read species data
CREATE POLICY "Enable read access for all users"
ON public.species FOR SELECT
USING (true);
-- Allow anyone to insert new species (for the API)
CREATE POLICY "Enable insert access for all users"
ON public.species FOR INSERT
WITH CHECK (true);
-- ============================================================
-- STEP 4: Verify RLS is enabled
-- ============================================================
ALTER TABLE public.species ENABLE ROW LEVEL SECURITY;
-- ============================================================
-- STEP 5: Verify the policies were created
-- ============================================================
SELECT
schemaname,
tablename,
policyname,
permissive,
cmd as operation,
with_check
FROM pg_policies
WHERE tablename = 'species'
ORDER BY policyname;
-- ============================================================
-- STEP 6: Test insert manually
-- ============================================================
-- Try inserting a test record to verify it works
-- INSERT INTO public.species (sno, species_name, species_type, location, latitude, longitude, added_by, notes)
-- VALUES (9999, 'Test Species', 'plant', 'QSC', 12.92000, 80.12100, 'test', 'Test insert');
--
-- -- If successful, delete the test record
-- DELETE FROM public.species WHERE sno = 9999;
|