Files
alva/supabase/migrations/20260128002241_82fa2e5e-38c0-4def-b849-ecc61f2e3787.sql
T
gpt-engineer-app[bot] 793d0e9a01 Changes
2026-01-28 00:22:52 +00:00

36 lines
1.1 KiB
SQL

-- Create orders table to store e-commerce orders
CREATE TABLE public.orders (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
order_number TEXT NOT NULL,
customer_email TEXT NOT NULL,
customer_name TEXT,
items JSONB NOT NULL DEFAULT '[]',
total_amount DECIMAL(10,2) NOT NULL,
currency TEXT NOT NULL DEFAULT 'SEK',
status TEXT NOT NULL DEFAULT 'pending',
shopify_checkout_id TEXT,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()
);
-- Enable RLS
ALTER TABLE public.orders ENABLE ROW LEVEL SECURITY;
-- Create policy for authenticated users (admins) to view all orders
CREATE POLICY "Authenticated users can view all orders"
ON public.orders
FOR SELECT
TO authenticated
USING (true);
-- Create policy for inserting orders (from edge function)
CREATE POLICY "Service role can insert orders"
ON public.orders
FOR INSERT
WITH CHECK (true);
-- Create trigger for updated_at
CREATE TRIGGER update_orders_updated_at
BEFORE UPDATE ON public.orders
FOR EACH ROW
EXECUTE FUNCTION public.update_updated_at_column();