create table public.order_reviews ( id uuid primary key default gen_random_uuid(), order_id text not null unique references public.orders (id) on delete cascade, rating smallint not null check (rating between 1 and 5), comment text not null check (char_length(btrim(comment)) between 1 and 2000), display_name text check (display_name is null or char_length(btrim(display_name)) between 1 and 60), photo_path text, status text not null default 'pending' check (status in ('pending', 'approved', 'hidden')), created_at timestamptz not null default now(), published_at timestamptz, check ((status = 'approved') = (published_at is not null)) ); create index order_reviews_approved_idx on public.order_reviews (published_at desc) where status = 'approved'; alter table public.order_reviews enable row level security; revoke all on table public.order_reviews from public, anon, authenticated; grant select, insert, update on table public.order_reviews to service_role; insert into storage.buckets (id, name, public, file_size_limit, allowed_mime_types) values ('order-review-photos', 'order-review-photos', false, 4194304, array['image/jpeg']);