-
Notifications
You must be signed in to change notification settings - Fork 182
/
script.sql
308 lines (264 loc) · 10.6 KB
/
script.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
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
use keyist;
drop table if exists color;
create table color
(
id int auto_increment
primary key,
name varchar(50) not null,
hex varchar(50) not null,
constraint color_hex_uindex
unique (hex),
constraint color_name_uindex
unique (name)
);
drop table if exists discount;
create table discount
(
id int auto_increment
primary key,
code varchar(240) not null,
discount_percent int not null,
status tinyint(1) default 1 not null,
constraint code
unique (code)
);
drop table if exists oauth_access_token;
create table oauth_access_token
(
token_id varchar(255) null,
token mediumblob null,
authentication_id varchar(255) not null
primary key,
user_name varchar(255) null,
client_id varchar(255) null,
authentication mediumblob null,
refresh_token varchar(255) null
);
drop table if exists oauth_approvals;
create table oauth_approvals
(
userId varchar(255) null,
clientId varchar(255) null,
scope varchar(255) null,
status varchar(10) null,
expiresAt timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP,
lastModifiedAt timestamp not null
);
drop table if exists oauth_client_details;
create table oauth_client_details
(
client_id varchar(255) not null
primary key,
resource_ids varchar(255) null,
client_secret varchar(255) null,
scope varchar(255) null,
authorized_grant_types varchar(255) null,
web_server_redirect_uri varchar(255) null,
authorities varchar(255) null,
access_token_validity int null,
refresh_token_validity int null,
additional_information varchar(4096) null,
autoapprove varchar(255) null
);
drop table if exists oauth_client_token;
create table oauth_client_token
(
token_id varchar(255) null,
token mediumblob null,
authentication_id varchar(255) not null
primary key,
user_name varchar(255) null,
client_id varchar(255) null
);
drop table if exists oauth_code;
create table oauth_code
(
code varchar(255) null,
authentication mediumblob null
);
drop table if exists oauth_refresh_token;
create table oauth_refresh_token
(
token_id varchar(255) not null,
token mediumblob null,
authentication mediumblob null
);
drop table if exists product_category;
create table product_category
(
id int auto_increment
primary key,
name varchar(50) not null,
constraint name
unique (name)
);
drop table if exists product;
create table product
(
id int auto_increment
primary key,
category_id int null,
sku varchar(50) not null,
name varchar(100) not null,
url varchar(100) not null,
long_desc text not null,
date_created timestamp default CURRENT_TIMESTAMP not null,
last_updated timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP,
unlimited tinyint(1) default 1 null,
constraint product_ibfk_1
foreign key (category_id) references product_category (id)
);
create index category_id
on product (category_id);
drop table if exists product_variant;
create table product_variant
(
id int auto_increment
primary key,
product_id int null,
color_id int not null,
width varchar(100) null,
height varchar(100) null,
price float(100, 2) not null,
composition varchar(259) null,
cargo_price float(100, 2) not null,
tax_percent int default 0 null,
sell_count int default 0 null,
stock int not null,
live tinyint(1) not null,
image varchar(250) null,
thumb varchar(250) null,
constraint color_id
foreign key (color_id) references color (id),
constraint product_id
foreign key (product_id) references product (id)
);
drop table if exists user;
create table user
(
id int auto_increment
primary key,
email varchar(500) not null,
password varchar(500) not null,
first_name varchar(50) null,
last_name varchar(50) null,
city varchar(90) null,
state varchar(20) null,
zip varchar(12) null,
email_verified tinyint(1) default 0 null,
registration_date timestamp default CURRENT_TIMESTAMP null,
phone varchar(20) null,
country varchar(20) null,
address varchar(100) null,
constraint email
unique (email)
);
drop table if exists cart;
create table cart
(
id int auto_increment
primary key,
user_id int null,
discount_id int null,
total_cart_price float default 0 not null,
total_cargo_price float default 0 not null,
total_price float default 0 not null,
date_created timestamp default CURRENT_TIMESTAMP not null,
constraint cart_ibfk_1
foreign key (user_id) references user (id),
constraint cart_ibfk_2
foreign key (discount_id) references discount (id)
);
create index discount_id
on cart (discount_id);
create index user_id
on cart (user_id);
drop table if exists cart_item;
create table cart_item
(
id int auto_increment
primary key,
cart_id int not null,
product_variant_id int null,
amount int not null,
constraint cart_item_ibfk_1
foreign key (cart_id) references cart (id),
constraint product_variant_id
foreign key (product_variant_id) references product_variant (id)
);
create index cart_id
on cart_item (cart_id);
drop table if exists orders;
create table orders
(
id int auto_increment
primary key,
user_id int not null,
ship_name varchar(100) not null,
ship_address varchar(100) not null,
billing_address varchar(100) not null,
city varchar(50) not null,
state varchar(50) not null,
zip varchar(20) null,
country varchar(50) not null,
phone varchar(20) not null,
total_price float not null,
total_cargo_price float not null,
discount_id int null,
date timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP,
shipped tinyint(1) default 0 not null,
cargo_firm varchar(100) null,
tracking_number varchar(80) null,
constraint orders_ibfk_1
foreign key (user_id) references user (id),
constraint orders_ibfk_2
foreign key (discount_id) references discount (id)
);
drop table if exists order_detail;
create table order_detail
(
id int auto_increment
primary key,
order_id int not null,
product_variant_id int null,
amount int not null,
constraint order_detail_ibfk_1
foreign key (order_id) references orders (id),
constraint product_variant_id_ibfk_1
foreign key (product_variant_id) references product_variant (id)
);
create index order_id
on order_detail (order_id);
create index discount_id
on orders (discount_id);
create index user_id
on orders (user_id);
drop table if exists password_reset_token;
create table password_reset_token
(
id int auto_increment
primary key,
token varchar(255) not null,
expiry_date timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP,
user_id int not null,
constraint user_id
unique (user_id),
constraint password_reset_token_ibfk_1
foreign key (user_id) references user (id)
);
drop table if exists verification_token;
create table verification_token
(
id int auto_increment
primary key,
token varchar(255) not null,
expiry_date timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP,
user_id int not null,
constraint verification_token_ibfk_1
foreign key (user_id) references user (id)
);
INSERT INTO keyist.oauth_client_details (client_id, resource_ids, client_secret, scope, authorized_grant_types, web_server_redirect_uri, authorities, access_token_validity, refresh_token_validity, additional_information, autoapprove) VALUES ('test', 'resource-server-rest-api', '$2a$04$v8DNBoc36pw4c7b7Xyq/aeSpGneF9WciZUI9FibVz0neksUcPBXVS', 'read,write', 'password,authorization_code,refresh_token,implicit', null, 'USER', 10800, 2592000, null, null);
INSERT INTO keyist.product_category (id, name) VALUES (1, 'Test');
INSERT INTO keyist.color (id, name, hex) VALUES (1, 'red', '#ff144b');
INSERT INTO keyist.product (id, category_id, sku, name, url, long_desc, date_created, last_updated, unlimited) VALUES (1, 1, '000-0001', 'Test', 'test', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry''s standard dummy text ever since the 1500s. ', '2018-05-18 09:50:48', '2020-10-22 01:55:43', 1);
INSERT INTO keyist.product_variant (id, product_id, color_id, width, height, price, composition, cargo_price, tax_percent, sell_count, stock, live, image, thumb) VALUES (1, 1, 1, '4cm', '10cm', 9.99, 'Copper 70%, Zinc 30%', 5, 10, 6, 1000, 1, 'image-url-here', 'image-url-here');