migration: add order_number and order_hash columns to orders
All checks were successful
Staging Build / build (push) Successful in 2m27s
All checks were successful
Staging Build / build (push) Successful in 2m27s
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
-- Migration: Add order_number and order_hash to orders table
|
||||
ALTER TABLE public.orders
|
||||
ADD COLUMN IF NOT EXISTS order_number TEXT,
|
||||
ADD COLUMN IF NOT EXISTS order_hash TEXT;
|
||||
|
||||
-- Update existing orders to have a unique order_number
|
||||
UPDATE public.orders
|
||||
SET order_number = 'RE-' || EXTRACT(YEAR FROM created_at)::text || '-' || floor(10000 + random() * 90000)::text
|
||||
WHERE order_number IS NULL;
|
||||
|
||||
-- Now add unique constraint and make it not null
|
||||
ALTER TABLE public.orders
|
||||
ALTER COLUMN order_number SET NOT NULL,
|
||||
ADD CONSTRAINT orders_order_number_key UNIQUE (order_number);
|
||||
|
||||
-- Notify PostgREST to reload schema cache
|
||||
NOTIFY pgrst, 'reload schema';
|
||||
Reference in New Issue
Block a user