erp-cicd/frontend/supabase/migrations/20250809182514_3fb1044b-42b3-493c-9399-2fe872cc8ba2.sql
Ali af6fd7bcad
All checks were successful
Build & Deploy Frontend / build-push-deploy (push) Successful in 1m45s
added some
2025-08-30 11:57:49 +05:30

18 lines
584 B
SQL

-- Allow authenticated users to create organizations they own
CREATE POLICY "Users can create organizations"
ON public.organizations
FOR INSERT TO authenticated
WITH CHECK (created_by = auth.uid());
-- Allow the creator to seed first admin membership for a new org
CREATE POLICY "Seed first org admin"
ON public.organization_members
FOR INSERT TO authenticated
WITH CHECK (
user_id = auth.uid()
AND role = 'admin'::public.user_role
AND NOT EXISTS (
SELECT 1 FROM public.organization_members m
WHERE m.org_id = organization_members.org_id AND m.deleted_at IS NULL
)
);