-
Notifications
You must be signed in to change notification settings - Fork 1
/
BasicMysql_Ecommerce_DB_1.sql
146 lines (128 loc) · 3.99 KB
/
BasicMysql_Ecommerce_DB_1.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
create table Users(
idUser varchar(40) primary key not null,
fullname varchar(40) not null,
birthdate date ,
inscriptionDate date,
username varchar(40) not null,
email varchar(40) not null,
password varchar(40) not null,
salt varchar(40) not null,
postalCode varchar(15),
direction varchar(120),
referenceDirection varchar(120),
coordPrimary varchar(120),
coordSecondary varchar(120)
);
/* service create user
create user
create wishlist
cretate bucket
-> we need a procedure
*/
insert into Users(idUser,fullname,username,email,password,salt,direction,referenceDirection)
value('user-1','señor cara de papa','carepapa1','carepapa@gmail.com','caradepapa123','132','calle 77, lote 45, los paperos','casa roja de carton');
select * from Users;
CREATE PROCEDURE procedure_after_create_user (idUser varchar(40), idWishlist varchar(40) , idBucket varchar(40))
BEGIN
insert into Wishlists(idWishlist,idUser)
values(idWishlist,idUser );
insert into Buckets(idBucket,idUser)
values(idBucket,idUser );
END
call procedure_after_create_user ('user-1', 'wishlist-1','bucket-1');
create table Products(
idProduct varchar(40) primary key not null,
nameProduct varchar(40) not null,
currentPrice decimal(5,2) not null,
state varchar(20) not null,
brand varchar(40),
category1 varchar(20),
category2 varchar(20),
category3 varchar(20),
category4 varchar(20),
urlImage1 varchar(120),
urlImage2 varchar(120),
urlImage3 varchar(120),
urlImage4 varchar(120),
`description` varchar(220),
offertPercent decimal(5,2),
typeProduct varchar(20),
espec varchar(500)
);
insert into Products(idProduct,nameProduct,brand,currentPrice,state,category1,category2,urlImage1,`description`,offertPercent,typeProduct)
value('product-1','polo','jaimito',15.5,'in sotck','clothes','tshirt','','este es un polo 100% algodon',5,'tshirt');
select * from Products;
/* service create product
create product
create rating
-> we need a procedure
*/
create table Cupons(
idCupon varchar(40) primary key not null,
code varchar(40) not null,
state varchar(20) not null,
idUserUsed varchar(40) not null,
foreign key (idUserUsed) references Users(idUser)
);
/*
expiration date
init date
*/
create table Orders(
idOrder varchar(40) primary key not null,
idUser varchar(40) not null,
stateOrder varchar(20) not null,
dateOrder date,
foreign key (idUser) references Users(idUser)
);
create table OrderItem(
idItem varchar(40) primary key not null,
idOrder varchar(40) not null,
idProduct varchar(40) not null,
quantity int not null,
foreign key (idProduct) references Products(idProduct),
foreign key (idOrder) references Orders(idOrder)
);
create table Wishlists(
idWishlist varchar(40) primary key not null,
idUser varchar(40) not null,
foreign key (idUser) references Users(idUser)
);
create table WishlistItem(
idItem varchar(40) primary key not null,
idWishlist varchar(40) not null,
idProduct varchar(40) not null,
foreign key (idWishlist) references Wishlists(idWishlist),
foreign key (idProduct) references Products(idProduct)
);
create table Buckets(
idBucket varchar(40) primary key not null,
idUser varchar(40) not null,
foreign key (idUser) references Users(idUser)
);
create table BucketItem(
idItem varchar(40) primary key not null,
idBucket varchar(40) not null,
idProduct varchar(40) not null,
foreign key (idBucket) references Buckets(idBucket),
foreign key (idProduct) references Products(idProduct)
);
/* additional */
create table ratingProduct(
idRating varchar(40) primary key not null,
idProduct varchar(40) not null,
star_1 int not null,
star_2 int not null,
star_3 int not null,
star_4 int not null,
star_5 int not null,
foreign key (idProduct) references Products(idProduct)
)
/*api calls*/
/*product API*/
/*get best products*/
select * from users u inner join buckets b ,wishlists w where u.idUser = b.idUser AND u.idUSer = 'user-1';
/*get product*/
select * from users u inner join buckets b ,wishlists w where u.idUser = b.idUser AND u.idUSer = 'user-1';
/*delete product*/
/*update product*/