3df6029f89
Adds anonymous order tracking via a unique public_token UUID on each order, a standalone React page at /track/:token, and a share button in OrderModal.
12 lines
532 B
SQL
12 lines
532 B
SQL
-- 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);
|