-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase_schema.sql
More file actions
92 lines (91 loc) · 3.88 KB
/
supabase_schema.sql
File metadata and controls
92 lines (91 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
-- WARNING: This schema is for context only and is not meant to be run.
-- Table order and constraints may not be valid for execution.
CREATE TABLE public.cart_items (
id uuid NOT NULL DEFAULT gen_random_uuid(),
user_id uuid NOT NULL DEFAULT auth.uid(),
product_id uuid NOT NULL,
quantity smallint NOT NULL DEFAULT '0'::smallint,
CONSTRAINT cart_items_pkey PRIMARY KEY (id),
CONSTRAINT cart_items_product_id_fkey FOREIGN KEY (product_id) REFERENCES public.products(id),
CONSTRAINT cart_items_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id)
);
CREATE TABLE public.categories (
id uuid NOT NULL DEFAULT gen_random_uuid(),
name character varying NOT NULL,
parent_id uuid,
is_popular boolean DEFAULT false,
CONSTRAINT categories_pkey PRIMARY KEY (id),
CONSTRAINT categories_parent_id_fkey FOREIGN KEY (parent_id) REFERENCES public.categories(id)
);
CREATE TABLE public.order_items (
id uuid NOT NULL DEFAULT gen_random_uuid(),
created_at timestamp with time zone NOT NULL DEFAULT now(),
order_id uuid NOT NULL,
product_id uuid NOT NULL,
quantity double precision,
price double precision,
CONSTRAINT order_items_pkey PRIMARY KEY (id),
CONSTRAINT order_items_order_id_fkey FOREIGN KEY (order_id) REFERENCES public.orders(id),
CONSTRAINT order_items_product_id_fkey FOREIGN KEY (product_id) REFERENCES public.products(id)
);
CREATE TABLE public.orders (
id uuid NOT NULL DEFAULT gen_random_uuid(),
created_at timestamp with time zone NOT NULL DEFAULT now(),
status character varying,
total_price double precision DEFAULT '0'::double precision,
shipping_address character varying,
payment_method character varying,
user_id uuid,
pickup_type text NOT NULL DEFAULT 'delivery'::text CHECK (pickup_type = ANY (ARRAY['delivery'::text, 'store_pickup'::text])),
pickup_store_id uuid,
pickup_window tstzrange,
CONSTRAINT orders_pkey PRIMARY KEY (id),
CONSTRAINT orders_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id),
CONSTRAINT orders_pickup_store_id_fkey FOREIGN KEY (pickup_store_id) REFERENCES public.stores(id)
);
CREATE TABLE public.payments (
id uuid NOT NULL DEFAULT uuid_generate_v4(),
order_id uuid,
user_id uuid,
amount numeric NOT NULL,
status text DEFAULT 'pending'::text CHECK (status = ANY (ARRAY['pending'::text, 'success'::text, 'failed'::text])),
method text,
transaction_id text,
created_at timestamp with time zone DEFAULT now(),
CONSTRAINT payments_pkey PRIMARY KEY (id),
CONSTRAINT payments_order_id_fkey FOREIGN KEY (order_id) REFERENCES public.orders(id),
CONSTRAINT payments_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id)
);
CREATE TABLE public.products (
id uuid NOT NULL DEFAULT gen_random_uuid(),
name character varying NOT NULL DEFAULT ''::character varying,
price double precision DEFAULT '0'::double precision,
description character varying DEFAULT ''::character varying,
image_url character varying DEFAULT ''::character varying,
is_available boolean NOT NULL,
category_id uuid,
slug text UNIQUE,
CONSTRAINT products_pkey PRIMARY KEY (id),
CONSTRAINT products_category_id_fkey FOREIGN KEY (category_id) REFERENCES public.categories(id)
);
CREATE TABLE public.stores (
id uuid NOT NULL DEFAULT gen_random_uuid(),
name text NOT NULL,
address_full text NOT NULL,
city text,
latitude double precision NOT NULL,
longitude double precision NOT NULL,
phone text,
services jsonb DEFAULT '[]'::jsonb,
opening_hours jsonb DEFAULT '{}'::jsonb,
is_active boolean NOT NULL DEFAULT true,
created_at timestamp with time zone NOT NULL DEFAULT now(),
updated_at timestamp with time zone NOT NULL DEFAULT now(),
CONSTRAINT stores_pkey PRIMARY KEY (id)
);
CREATE TABLE public.user_roles (
user_id uuid NOT NULL,
role text NOT NULL DEFAULT '''user'''::text,
CONSTRAINT user_roles_pkey PRIMARY KEY (user_id),
CONSTRAINT user_roles_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id)
);