-- 2026-04-29: 후기 이미지 저장용 Supabase Storage bucket + RLS
-- 적용: Supabase Studio → Storage 또는 SQL Editor에서 1회 실행

-- 1. bucket 생성 (이미 있으면 무시)
insert into storage.buckets (id, name, public)
values ('review-images', 'review-images', true)
on conflict (id) do nothing;

-- 2. RLS — public read (anon이 업로드한 이미지 누구나 볼 수 있음)
do $$
begin
  if not exists (
    select 1 from pg_policies
    where schemaname = 'storage' and tablename = 'objects' and policyname = 'review_images_public_read'
  ) then
    create policy "review_images_public_read"
      on storage.objects for select
      using (bucket_id = 'review-images');
  end if;
end$$;

-- 3. RLS — public insert (anon 사용자도 후기 이미지 업로드 가능)
do $$
begin
  if not exists (
    select 1 from pg_policies
    where schemaname = 'storage' and tablename = 'objects' and policyname = 'review_images_public_insert'
  ) then
    create policy "review_images_public_insert"
      on storage.objects for insert
      with check (bucket_id = 'review-images');
  end if;
end$$;
