Changes
This commit is contained in:
@@ -14,6 +14,48 @@ export type Database = {
|
||||
}
|
||||
public: {
|
||||
Tables: {
|
||||
orders: {
|
||||
Row: {
|
||||
created_at: string
|
||||
currency: string
|
||||
customer_email: string
|
||||
customer_name: string | null
|
||||
id: string
|
||||
items: Json
|
||||
order_number: string
|
||||
shopify_checkout_id: string | null
|
||||
status: string
|
||||
total_amount: number
|
||||
updated_at: string
|
||||
}
|
||||
Insert: {
|
||||
created_at?: string
|
||||
currency?: string
|
||||
customer_email: string
|
||||
customer_name?: string | null
|
||||
id?: string
|
||||
items?: Json
|
||||
order_number: string
|
||||
shopify_checkout_id?: string | null
|
||||
status?: string
|
||||
total_amount: number
|
||||
updated_at?: string
|
||||
}
|
||||
Update: {
|
||||
created_at?: string
|
||||
currency?: string
|
||||
customer_email?: string
|
||||
customer_name?: string | null
|
||||
id?: string
|
||||
items?: Json
|
||||
order_number?: string
|
||||
shopify_checkout_id?: string | null
|
||||
status?: string
|
||||
total_amount?: number
|
||||
updated_at?: string
|
||||
}
|
||||
Relationships: []
|
||||
}
|
||||
profiles: {
|
||||
Row: {
|
||||
address: string | null
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
-- 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();
|
||||
Reference in New Issue
Block a user