erp-cicd/my-access-hub-main/supabase/migrations/20250809182440_50f762fb-ff45-472f-9175-1938c7efb145.sql
Ali 20e95c2fb6
Some checks failed
Build & Deploy Frontend / build-push-deploy (push) Failing after 15s
pushing all
2025-08-30 11:51:11 +05:30

19 lines
613 B
SQL

-- Allow authenticated users to create organizations they own
CREATE POLICY IF NOT EXISTS "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 IF NOT EXISTS "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
)
);