-- Add public_token column to orders for anonymous order tracking ALTER TABLE orders ADD COLUMN IF NOT EXISTS public_token UUID DEFAULT gen_random_uuid(); -- Backfill existing orders that have NULL public_token UPDATE orders SET public_token = gen_random_uuid() WHERE public_token IS NULL; -- Allow anon role to read orders if they know the public_token -- (filtered further in app code via .eq('public_token', token)) CREATE POLICY "orders_read_by_public_token" ON orders FOR SELECT TO anon USING (public_token IS NOT NULL);