-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.sql
212 lines (189 loc) · 5.75 KB
/
schema.sql
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
-- User table
create table _user
(
user_id bigint not null
primary key,
create_dt timestamp not null,
email varchar(255) not null
constraint uk_k11y3pdtsrjgy8w9b6q4bjwrx
unique,
password varchar(255) not null,
role varchar(10) not null,
update_dt timestamp not null
);
alter table address
owner to "ved-asole";
-- Customer table
create table customer
(
customer_id bigint not null
primary key,
create_dt timestamp not null,
email varchar(255) not null
constraint uk_dwk6cx0afu8bs9o4t536v1j5v
unique,
first_name varchar(20) not null,
last_name varchar(20) not null,
phone_number varchar(255) not null,
update_dt timestamp not null,
address_id bigint
constraint "FKp0ork25utpkdwuhi874nf19cc"
references address,
user_id bigint not null
constraint uk_j7ja2xvrxudhvssosd4nu1o92
unique
constraint "FKk2b4lf83ck1rq7vmfuver6e1c"
references _user
);
alter table customer
owner to "ved-asole";
-- Category Table
create table category
(
category_id bigint not null
primary key,
active boolean not null,
create_dt timestamp not null,
"desc" varchar(1000),
image varchar(255) not null,
name varchar(20) not null,
update_dt timestamp not null,
parent_category_id bigint
constraint "FK4wqwi3wgsrq5kka9k94vc5u2i"
references category
);
alter table category
owner to "ved-asole";
-- Product table
create table product
(
product_id bigint not null
primary key,
create_dt timestamp not null,
"desc" varchar(1000),
discount double precision
constraint product_discount_check
check (discount >= (0)::double precision),
image varchar(255) not null,
name varchar(255) not null,
price double precision not null
constraint product_price_check
check (price >= (0)::double precision),
qty_in_stock integer
constraint product_qty_in_stock_check
check (qty_in_stock >= 0),
sku varchar(255) not null
constraint uk_q1mafxn973ldq80m1irp3mpvq
unique,
update_dt timestamp,
category_id bigint not null
constraint "FK7l29ekt1x29jup80y2iigimyy"
references category
);
alter table product
owner to "ved-asole";
create index product_name_idx
on product (name);
create index product_desc_idx
on product ("desc");
create index product_name_desc_idx
on product (name, "desc");
create index product_category_idx
on product (category_id);
-- Address table
alter table _user
owner to "ved-asole";
create table address
(
address_id bigint not null
primary key,
add_line1 varchar(100) not null,
add_line2 varchar(100),
city varchar(50) not null,
country varchar(50) not null,
create_dt timestamp not null,
postal_code integer not null,
state varchar(50) not null,
update_dt timestamp not null
);
--Cart Item table
create table cart_item
(
cart_item_id bigint not null
primary key,
create_dt timestamp not null,
quantity bigint not null
constraint cart_item_quantity_check
check (quantity >= 0),
update_dt timestamp,
product_id bigint not null
constraint "FKbqjyyaj7ikkmpvm4vw2l64y2s"
references product,
cart_id bigint not null
constraint "FKlmddnw6pd7gder2x4r07f1ves"
references cart
);
alter table cart_item
owner to "ved-asole";
-- Cart table
create table cart
(
cart_id bigint not null
primary key,
create_dt timestamp not null,
discount double precision
constraint cart_discount_check
check (discount >= (0)::double precision),
total double precision not null
constraint cart_total_check
check (total >= (0)::double precision),
update_dt timestamp,
customer_id bigint not null
constraint uk_867x3yysb1f3jk41cv3vsoejj
unique
constraint "FKjkl19yyf10l5tb7j5npdhgy3b"
references customer
);
alter table cart
owner to "ved-asole";
-- Order Item table
create table order_item
(
order_item_id bigint not null
primary key,
create_dt timestamp not null,
quantity bigint not null
constraint order_item_quantity_check
check (quantity >= 0),
update_dt timestamp,
order_id bigint not null
constraint "FKl1bqqbilx1hdy29vykrqkgu3p"
references "order",
product_id bigint not null
constraint "FKsxgfmcie6oo67uxtk9hqk02mq"
references product
);
-- Order table
create table "order"
(
order_id bigint not null
primary key,
create_dt timestamp not null,
order_status varchar(30) not null,
total double precision not null
constraint order_total_check
check (total >= (0)::double precision),
update_dt timestamp,
address_id bigint not null
constraint "FKjm6o0lh0tgj5m2tshjbaw5moj"
references address,
customer_id bigint not null
constraint "FKk1m6gjs4m7rtgb5lw01g35yca"
references customer
);
alter table "order"
owner to "ved-asole";
create index order_customer_id_idx
on "order" (customer_id);
create index order_customer_id_order_id_idx
on "order" (customer_id, order_id);