diff --git a/src/integrations/supabase/types.ts b/src/integrations/supabase/types.ts index 9022231..59198fc 100644 --- a/src/integrations/supabase/types.ts +++ b/src/integrations/supabase/types.ts @@ -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 diff --git a/supabase/migrations/20260128002241_82fa2e5e-38c0-4def-b849-ecc61f2e3787.sql b/supabase/migrations/20260128002241_82fa2e5e-38c0-4def-b849-ecc61f2e3787.sql new file mode 100644 index 0000000..1d1997a --- /dev/null +++ b/supabase/migrations/20260128002241_82fa2e5e-38c0-4def-b849-ecc61f2e3787.sql @@ -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(); \ No newline at end of file