
ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS image_url text;

INSERT INTO storage.buckets (id, name, public)
VALUES ('customer-images', 'customer-images', true)
ON CONFLICT (id) DO NOTHING;

DROP POLICY IF EXISTS "Public can view customer images" ON storage.objects;
CREATE POLICY "Public can view customer images"
ON storage.objects FOR SELECT
USING (bucket_id = 'customer-images');

DROP POLICY IF EXISTS "Staff can upload customer images" ON storage.objects;
CREATE POLICY "Staff can upload customer images"
ON storage.objects FOR INSERT TO authenticated
WITH CHECK (bucket_id = 'customer-images' AND public.is_staff(auth.uid()));

DROP POLICY IF EXISTS "Staff can update customer images" ON storage.objects;
CREATE POLICY "Staff can update customer images"
ON storage.objects FOR UPDATE TO authenticated
USING (bucket_id = 'customer-images' AND public.is_staff(auth.uid()));

DROP POLICY IF EXISTS "Staff can delete customer images" ON storage.objects;
CREATE POLICY "Staff can delete customer images"
ON storage.objects FOR DELETE TO authenticated
USING (bucket_id = 'customer-images' AND public.is_staff(auth.uid()));
