-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemandi_new.sql
293 lines (237 loc) · 7.59 KB
/
emandi_new.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
create table ADMIN(
admin_name VARCHAR(50) PRIMARY KEY,
password VARCHAR(150) NOT NULL
);
create table STATE(
state_id TINYINT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(25) UNIQUE NOT NULL
);
create table CITY(
city_id SMALLINT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(25) NOT NULL,
state_id TINYINT NOT NULL,
UNIQUE(state_id, name),
FOREIGN KEY (state_id)
REFERENCES STATE(state_id)
ON DELETE CASCADE
);
create table VENDOR (
--- PROFILE ---
-- SIGN UP VIA OTP --
vendor_id INT AUTO_INCREMENT PRIMARY KEY,
contact BIGINT UNIQUE NOT NULL,
-- PROFILE --
type VARCHAR(25),
name VARCHAR(25),
state_id TINYINT,
city_id SMALLINT,
pin_code INT,
address VARCHAR(1000),
profile_picture VARCHAR(1000),
-- AUTOMATIC --
reg_timestamp TIMESTAMP NOT NULL DEFAULT NOW(),
unreg_timestamp TIMESTAMP,
--- DEVICE RELATED --- SENT ON LOGIN/SIGNUP
device_fcm_token VARCHAR(500),
--- ORDER RELATED --- HANDLED INTERNALLY
orders_recieved INT DEFAULT 0,
orders_cancelled_by_user INT DEFAULT 0,
orders_cancelled_by_vendor INT DEFAULT 0,
order_domino_number TINYINT DEFAULT 0, -- after a limit, don't allow cancellation
--- BAN RELATED --- HANDLED BY ADMIN
defaulter_status VARCHAR(30) DEFAULT "NO_ISSUE", -- 0: no issue, 1: suspended, 2: banned
--- BAN RELATED --- HANDLED INTERNALLY
defaulter_timestamp TIMESTAMP,
defaulter_period TIMESTAMP,
FOREIGN KEY (state_id)
REFERENCES STATE(state_id)
ON DELETE CASCADE,
FOREIGN KEY (city_id)
REFERENCES CITY(city_id)
ON DELETE CASCADE
);
create table USER(
--- SIGNUP LOGIN ----
user_id INT PRIMARY KEY AUTO_INCREMENT,
device_fcm_token VARCHAR(500),
contact BIGINT UNIQUE NOT NULL,
--- PROFILE ---
name VARCHAR(25),
state_id TINYINT,
city_id SMALLINT,
pin_code INT,
reg_timestamp TIMESTAMP NOT NULL DEFAULT NOW(),
unreg_timestamp TIMESTAMP,
address VARCHAR(1000),
profile_picture VARCHAR(1000),
--- DEVICE RELATED ---
--- ORDER RELATED --- HANDLED INTERNALLY
orders_issued INT DEFAULT 0,
orders_cancelled_by_user INT DEFAULT 0,
order_domino_number TINYINT DEFAULT 0, -- after a limit, don't allow cancellation
--- BAN RELATED --- HANDLED BY ADMIN
defaulter_status VARCHAR(30) DEFAULT "NO_ISSUE", -- 0: no issue, 1: suspended, 2: banned
--- BAN RELATED --- HANDLED INTERNALLY
defaulter_timestamp TIMESTAMP,
defaulter_period TIMESTAMP,
FOREIGN KEY (state_id)
REFERENCES STATE(state_id)
ON DELETE CASCADE,
FOREIGN KEY (city_id)
REFERENCES CITY(city_id)
ON DELETE CASCADE
);
create table OTP_SIGNUP(
subscriber_type VARCHAR(20) NOT NULL,
contact BIGINT NOT NULL,
otp INT NOT NULL,
reg_timestamp TIMESTAMP DEFAULT NOW()
);
create table OTP_LOGIN(
subscriber_id INT NOT NULL,
subscriber_type VARCHAR(20) NOT NULL,
contact BIGINT NOT NULL,
otp INT NOT NULL,
reg_timestamp TIMESTAMP DEFAULT NOW()
);
---- in dev db ----
-- relates distributor participation in sale
-- create table SALE_HISTORY(
-- vendor_id INT NOT NULL,
-- sale_id INT NOT NULL,
-- sale_status BOOLEAN DEFAULT 0
-- );
-- relates distributor and consumer
create table CROP_TYPE(
crop_type_id INT PRIMARY KEY AUTO_INCREMENT,
crop_type_name VARCHAR(200) NOT NULL,
crop_class VARCHAR(200) NOT NULL DEFAULT "OTHER"
);
create table CROP(
crop_id INT PRIMARY KEY AUTO_INCREMENT,
vendor_id INT NOT NULL,
crop_qty DECIMAL(10,2) UNSIGNED NOT NULL,
crop_price DECIMAL(10,2) UNSIGNED NOT NULL,
crop_name VARCHAR(200) NOT NULL,
crop_type_id INT,
packed_timestamp TIMESTAMP DEFAULT NOW(),
exp_timestamp TIMESTAMP DEFAULT "1999-01-01 00:00:00",
description VARCHAR(200),
FOREIGN KEY (crop_type_id)
REFERENCES CROP_TYPE(crop_type_id),
FOREIGN KEY (vendor_id)
REFERENCES VENDOR(vendor_id)
ON DELETE CASCADE
);
-- relates custumer to the choosen product
create table CART(
item_id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT NOT NULL,
crop_id INT NOT NULL,
item_qty DECIMAL(10,2) UNSIGNED NOT NULL,
item_cost DECIMAL(10,2),
UNIQUE(crop_id, user_id),
FOREIGN KEY (crop_id)
REFERENCES CROP(crop_id)
ON DELETE CASCADE,
FOREIGN KEY (user_id)
REFERENCES USER(user_id)
ON DELETE CASCADE
);
create table ORDERS(
order_id INT PRIMARY KEY AUTO_INCREMENT,
issue_timestamp TIMESTAMP DEFAULT NOW(),
user_id INT NOT NULL,
delivery_address VARCHAR(300) NOT NULL,
vendor_id INT NOT NULL,
order_status VARCHAR(20) DEFAULT "PENDING",
FOREIGN KEY (user_id)
REFERENCES USER(user_id)
ON DELETE CASCADE,
FOREIGN KEY (vendor_id)
REFERENCES VENDOR(vendor_id)
ON DELETE CASCADE
);
-- relates the order to the product
create table ORDERED_ITEM(
order_id INT NOT NULL,
crop_id INT NOT NULL,
item_qty DECIMAL(10,2) UNSIGNED NOT NULL,
item_freezed_cost DECIMAL(10,2) UNSIGNED NOT NULL,
FOREIGN KEY (order_id)
REFERENCES ORDERS(order_id)
ON DELETE CASCADE,
FOREIGN KEY (crop_id)
REFERENCES CROP(crop_id)
ON DELETE CASCADE
);
-- create table OFFER(
-- offer_id INT AUTO_INCREMENT,
-- vendor_id INT NOT NULL,
-- crop_id INT NOT NULL,
-- new_price DECIMAL(10,2),
-- discount_precentage DECIMAL(4,2),
-- status BOOLEAN DEFAULT 1, -- 0: off 1:on
-- reg_timestamp TIMESTAMP DEFAULT NOW(),
-- offer_period TIMESTAMP
-- );
-- create table SALE(
-- sale_id INT AUTO_INCREMENT,
-- crop_type_id INT,
-- new_price DECIMAL(10,2),
-- discount_precentage DECIMAL(4,2),
-- reg_timestamp TIMESTAMP DEFAULT NOW(),
-- sale_period TIMESTAMP
-- );
create table NOTIFICATION(
vendor_id INT,
user_id INT,
device_fcm_token INT,
message VARCHAR(300) NOT NULL,
issue_timestamp TIMESTAMP DEFAULT NOW(),
view_status BOOLEAN DEFAULT 0,
view_timestamp TIMESTAMP
);
create table COMPLAINT(
complaint_id INT AUTO_INCREMENT,
order_id INT NOT NULL,
type VARCHAR(200),
status TINYINT DEFAULT 0, -- 0: OPEN, 1: CLOSED, 2: REOPEN
reg_timestamp TIMESTAMP NOT NULL DEFAULT NOW(),
resolve_timestamp TIMESTAMP
);
create table PROOF(
proof_id INT AUTO_INCREMENT,
complaint_id INT,
type TINYINT, -- 0: IMAGE, 1:PDF, 3:OTHER
resource_url VARCHAR(100),
description VARCHAR(500)
);
-- crop type table
-- let uri = https://emandi-api.herokuapp.com/
-- `('Potato','VEGETABLES','${uri}/'),
-- ('Tomato','VEGETABLES','${uri}/'),
-- ('Onion','VEGETABLES',,'${uri}/'),
-- ('Lady Finger','VEGETABLES','${uri}/'),
-- ('Apple','FRUITS','${uri}/'),
-- ('Banana','FRUITS','${uri}/'),
-- ('Mango','FRUITS','${uri}/'),
-- ('Orange','FRUITS','${uri}/'),
-- ('Rice','GRAINS','${uri}/'),
-- ('Wheat','GRAINS','${uri}/'),
-- ('Masoor Dal','GRAINS','${uri}/'),
-- ('Maize','GRAINS','${uri}/')`
/**
('Garlic','VEGETABLES','https://emandi-api.herokuapp.com//defaults/crop_type/vegetables/garlic.jpg'),
('Okra','VEGETABLES','https://emandi-api.herokuapp.com//defaults/crop_type/vegetables/okra.jpg'),
('Cucumber','VEGETABLES',,'https://emandi-api.herokuapp.com//defaults/crop_type/vegetables/cucumber.jpg'),
('Peas','VEGETABLES','https://emandi-api.herokuapp.com//defaults/crop_type/vegetables/frozen_peas.jpg'),
('Apple','FRUITS','https://emandi-api.herokuapp.com//defaults/crop_type/fruits/apple.jpg'),
('Banana','FRUITS','https://emandi-api.herokuapp.com//defaults/crop_type/fruits/banana.jpg'),
('Grapes','FRUITS','https://emandi-api.herokuapp.com//defaults/crop_type/fruits/grapes.jpg'),
('Orange','FRUITS','https://emandi-api.herokuapp.com//defaults/crop_type/fruits/orange.jpg'),
('Barley','GRAINS','https://emandi-api.herokuapp.com//defaults/crop_type/grains/barley.jpg'),
('Oats','GRAINS','https://emandi-api.herokuapp.com//defaults/crop_type/grains/oats.jpg'),
('Quinoa','GRAINS','https://emandi-api.herokuapp.com//defaults/crop_type/grains/quinoa.jpg'),
('Rice','GRAINS','https://emandi-api.herokuapp.com//defaults/crop_type/grains/rice.jpg')
*/