erp-cicd/frontend/supabase/migrations/20250808171640_551ea26a-1f6f-427f-8372-fcbec5ee3024.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

30 lines
1.0 KiB
SQL

-- Create storage bucket for invoices
INSERT INTO storage.buckets (id, name, public) VALUES ('invoices', 'invoices', false);
-- Create RLS policies for invoice files
CREATE POLICY "Users can view their own invoices"
ON storage.objects
FOR SELECT
USING (bucket_id = 'invoices' AND auth.uid()::text = (storage.foldername(name))[1]);
CREATE POLICY "Admin and finance can upload invoices"
ON storage.objects
FOR INSERT
WITH CHECK (bucket_id = 'invoices' AND can_manage_data(auth.uid()));
CREATE POLICY "Admin and finance can update invoices"
ON storage.objects
FOR UPDATE
USING (bucket_id = 'invoices' AND can_manage_data(auth.uid()));
CREATE POLICY "Admin can delete invoices"
ON storage.objects
FOR DELETE
USING (bucket_id = 'invoices' AND has_role(auth.uid(), 'admin'::app_role));
-- Add invoice file URL field to services table
ALTER TABLE public.services
ADD COLUMN invoice_file_url TEXT;
-- Add comment to the new column
COMMENT ON COLUMN public.services.invoice_file_url IS 'URL of uploaded invoice file in storage';