Branchwell

Lumen & Gesso / website · lumengesso.com / supabase / migrations / 20261115190226_add_order_reviews.sql

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