Add orders table in backend
Introduced a new Supabase orders table with fields for order details, added RLS policies, and a trigger to update timestamps. Updated generated types to include full CRUD shape for orders. X-Lovable-Edit-ID: edt-53ec8b01-5fdb-4c55-85a1-62b1000f26a4
This commit is contained in:
@@ -14,6 +14,48 @@ export type Database = {
|
|||||||
}
|
}
|
||||||
public: {
|
public: {
|
||||||
Tables: {
|
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: {
|
profiles: {
|
||||||
Row: {
|
Row: {
|
||||||
address: string | null
|
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