Repository navigation
Expand file tree
/
Copy pathdatabase.sql
More file actions
96 lines (75 loc) · 2.16 KB
/
Copy pathdatabase.sql
File metadata and controls
96 lines (75 loc) · 2.16 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
DROP DATABASE IF EXISTS crunchy_food;
CREATE DATABASE crunchy_food;
USE crunchy_food;
CREATE TABLE users (
user_id INT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(100) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
user_type ENUM('user','admin') DEFAULT 'user',
address VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE menu_items (
item_id INT AUTO_INCREMENT PRIMARY KEY,
item_name VARCHAR(100) NOT NULL,
price DECIMAL(10,2) NOT NULL,
description TEXT,
image VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE cart (
cart_id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
item_id INT NOT NULL,
item_name VARCHAR(100) NOT NULL,
item_price DECIMAL(10,2) NOT NULL,
quantity INT NOT NULL DEFAULT 1,
total_price DECIMAL(10,2) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id)
REFERENCES users(user_id)
ON DELETE CASCADE,
FOREIGN KEY (item_id)
REFERENCES menu_items(item_id)
ON DELETE CASCADE,
INDEX(user_id),
INDEX(item_id)
);
CREATE TABLE orders (
order_id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
total_price DECIMAL(10,2) NOT NULL,
status ENUM(
'Pending',
'Preparing',
'Out for Delivery',
'Delivered',
'Cancelled'
) DEFAULT 'Pending',
payment_method ENUM(
'Cash on Delivery',
'Online Payment'
) DEFAULT 'Cash on Delivery',
order_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id)
REFERENCES users(user_id)
ON DELETE CASCADE,
INDEX(user_id)
);
CREATE TABLE order_items (
order_item_id INT AUTO_INCREMENT PRIMARY KEY,
order_id INT NOT NULL,
item_id INT NOT NULL,
item_name VARCHAR(100) NOT NULL,
item_price DECIMAL(10,2) NOT NULL,
quantity INT NOT NULL,
total_price DECIMAL(10,2) NOT NULL,
FOREIGN KEY (order_id)
REFERENCES orders(order_id)
ON DELETE CASCADE,
FOREIGN KEY (item_id)
REFERENCES menu_items(item_id)
ON DELETE CASCADE,
INDEX(order_id),
INDEX(item_id)
);