-- Allow external users to insert/update deliveries (upsert) and insert delivery_files
create policy "External inserts deliveries" on public.deliveries
  for insert with check (get_my_role() = 'external');

create policy "External updates deliveries" on public.deliveries
  for update using (get_my_role() = 'external');

create policy "External inserts delivery_files" on public.delivery_files
  for insert with check (get_my_role() = 'external');

-- Allow external users to upload to deliveries storage bucket
create policy "External inserts deliveries storage" on storage.objects
  for insert to authenticated with check (bucket_id = 'deliveries' and get_my_role() = 'external');
