-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproduction-db.sql
More file actions
326 lines (272 loc) · 7.75 KB
/
Copy pathproduction-db.sql
File metadata and controls
326 lines (272 loc) · 7.75 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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
CREATE SEQUENCE account_seq START 1000;
CREATE SEQUENCE brand_seq START 1000;
CREATE SEQUENCE category_seq START 1000;
CREATE SEQUENCE customer_seq START 1000;
CREATE SEQUENCE customer_basket_seq START 1000;
CREATE SEQUENCE customer_order_seq START 1000;
CREATE SEQUENCE customer_order_address_id_seq START 1000;
CREATE SEQUENCE product_seq START 1000;
CREATE SEQUENCE customer_review_review_id_seq START 1000;
CREATE SEQUENCE store_seq START 1000;
CREATE SEQUENCE customer_order_item_seq START 1000;
CREATE SEQUENCE stock_seq START 1000;
create table account
(
account_id integer default nextval('account_seq'::regclass) not null
constraint account_pkey
primary key,
email varchar(64) not null,
password varchar(64) not null,
deleted boolean not null,
deleted_at date
);
create table brand
(
brand_id integer default nextval('brand_seq'::regclass) not null
constraint brand_pkey
primary key,
brand_name varchar(64) not null
);
create table category
(
category_id integer default nextval('category_seq'::regclass) not null
constraint category_pkey
primary key,
category_name varchar(32) not null
);
create table customer
(
customer_id integer default nextval('customer_seq'::regclass) not null
constraint customer_pkey
primary key,
account_id integer not null
constraint customer_account_id_key
unique
constraint customer_account_id_fkey
references account
on delete cascade,
first_name varchar(32) not null,
last_name varchar(32) not null,
profile_picture_url text not null,
phone_number varchar(48)
);
create table customer_basket
(
basket_id integer default nextval('customer_basket_seq'::regclass) not null
constraint customer_basket_pkey
primary key,
customer_id integer not null
constraint customer_basket_customer_id_key
unique
constraint customer_basket_customer_id_fkey
references customer
on delete cascade
);
create table postal_service
(
service_id integer not null
constraint postal_service_pkey
primary key,
postalservicename varchar(32) not null,
price double precision not null,
avg_delivery_day integer
);
create table customer_order
(
order_id integer default nextval('customer_order_seq'::regclass) not null
constraint customer_order_pkey
primary key,
customer_id integer
constraint customer_order_customer_id_fkey
references customer,
receiver_first varchar(32) not null,
receiver_last varchar(32) not null,
phone_number varchar(32) not null,
optional_mail varchar(64),
postal_service_id integer
constraint customer_order_postal_service_id_fkey
references postal_service
on delete set null,
coupon_discount integer not null,
order_status varchar(32) not null,
order_date date not null,
required_date date not null,
shipped_date date not null,
additional_note text,
total_price double precision not null,
cargo_price double precision not null
);
create index idx_customer_order_customer_id
on customer_order (customer_id);
create table customer_order_address
(
id integer default nextval('customer_order_address_id_seq'::regclass) not null
constraint customer_order_address_pkey
primary key,
order_id integer not null
constraint customer_order_address_order_id_key
unique
constraint customer_order_address_order_id_fkey
references customer_order
on delete cascade,
country_tag varchar(4) not null,
province varchar(64) not null,
district varchar(64) not null,
neighborhood varchar(64) not null,
destination_zip_code varchar(12) not null,
address_text_primary text not null,
address_text_secondary text
);
create table product
(
product_id integer default nextval('product_seq'::regclass) not null
constraint product_pkey
primary key,
product_name varchar(128) not null,
brand_id integer not null
constraint product_brand_id_fkey
references brand,
category_id integer not null
constraint product_category_id_fkey
references category,
sub_type varchar(16) not null,
product_color varchar(16) not null,
product_image text not null,
product_width double precision not null,
product_height double precision not null,
product_weight double precision not null,
box_pieces integer not null,
model_year integer not null,
list_price double precision not null,
discount integer not null,
description text not null,
listed smallint not null
);
create table basket_item
(
basket_item_id integer not null
constraint basket_item_pkey
primary key,
basket_id integer not null
constraint basket_item_basket_id_fkey
references customer_basket
on delete cascade,
product_id integer not null
constraint basket_item_product_id_fkey
references product
on delete cascade,
amount integer not null
);
create table customer_review
(
review_id integer default nextval('customer_review_review_id_seq'::regclass) not null
constraint customer_review_pkey
primary key,
customer_id integer not null
constraint customer_review_customer_id_fkey
references customer
on delete cascade,
customer_comment text not null,
customer_rating double precision not null,
product_id integer not null
constraint customer_review_product_id_fkey
references product
on delete cascade,
reply_review_id integer
);
create index idx_customer_review_customer_id
on customer_review (customer_id);
create index idx_customer_review_product_id
on customer_review (customer_id);
create index idx_product_list_price
on product (list_price);
create index idx_product_name
on product (product_name);
create table product_sales_statistic
(
product_id integer not null
constraint product_sales_statistic_pkey
primary key
constraint product_sales_statistic_product_id_fkey
references product
on delete cascade,
number_sold integer not null,
product_rating double precision not null,
number_viewed integer not null,
date_added date not null
);
create table store
(
store_id integer default nextval('store_seq'::regclass) not null
constraint store_pkey
primary key,
store_name varchar(64) not null,
phone_number varchar(48) not null,
email varchar(64) not null
);
alter table store owner to service;
create table customer_order_item
(
customer_order_item_id integer default nextval('customer_order_item_seq'::regclass) not null
constraint customer_order_item_pkey
primary key,
order_id integer
constraint customer_order_item_order_id_fkey
references customer_order
on delete cascade,
product_id integer not null
constraint customer_order_item_product_id_fkey
references product,
quantity integer not null,
list_price double precision not null,
product_discount integer not null,
store_id integer
constraint customer_order_item_store_id_fkey
references store
on delete set null
);
create table stock
(
stock_id integer default nextval('stock_seq'::regclass) not null
constraint stock_pkey
primary key,
store_id integer not null
constraint stock_store_id_fkey
references store
on delete cascade,
product_id integer not null
constraint stock_product_id_fkey
references product
on delete cascade,
quantity integer not null
);
create index idx_stock_product_id
on stock (product_id);
create table store_address
(
store_id integer not null
constraint store_address_pkey
primary key
constraint store_address_store_id_fkey
references store
on delete cascade,
country_tag varchar(4) not null,
province varchar(64) not null,
district varchar(64) not null,
neighborhood varchar(64) not null,
zip_code varchar(32) not null,
address_text_primary text not null,
address_text_secondary text
);
create index idx_store_address_zip_code
on store_address (zip_code);
create table store_sales_statistic
(
store_id integer not null
constraint store_sales_statistic_pkey
primary key
constraint store_sales_statistic_store_id_fkey
references store
on delete cascade,
item_sold integer not null
);