-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprerequisites.py
More file actions
122 lines (106 loc) · 2.9 KB
/
prerequisites.py
File metadata and controls
122 lines (106 loc) · 2.9 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
import mysql.connector
# Connect to the MySQL database
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="password",
database="db_name"
)
cursor = mydb.cursor()
#Items Table and Data
items_data = [
(101, 'Arabica', 3),
(102, 'Robusta', 2.50),
(103, 'Excelsa', 4),
(104, 'Liberica', 1)
]
cursor.execute("""
CREATE TABLE items (
item_no INT PRIMARY KEY,
item_name VARCHAR(30),
price DECIMAL(5,2)
)
""")
insert_query = "INSERT INTO items (item_no, item_name, price) VALUES(%s, %s, %s)"
cursor.executemany(insert_query, items_data)
#Addons Table and Data
add_ons_data = [
(201, 'Coco Fudge', 0.50),
(202, 'Whip Cream', 0.10),
(203, 'Vanilla Extract', 0.30),
(204, 'Cinnamon and Nutmeg', 0.05),
(205, 'None', 0)
]
cursor.execute("""
CREATE TABLE add_ons (
addon_no INT PRIMARY KEY,
addon_name VARCHAR(30),
price DECIMAL(5,2)
)
""")
insert_query_add_ons = "INSERT INTO add_ons (addon_no, addon_name, price) VALUES (%s, %s, %s)"
cursor.executemany(insert_query_add_ons, add_ons_data)
#Milk Table and Data
milk_data =[
(1001, 'Coconut', 0.10),
(1002, 'Almond', 0.30),
(1003, 'Regular', 0.05),
(1004, 'Soy Milk', 0.20)
]
cursor.execute("""
CREATE TABLE milk (
milk_no INT PRIMARY KEY,
milk_type VARCHAR(30),
price DECIMAL(5,2)
)
""")
insert_query_milk = "INSERT INTO milk (milk_no, milk_type, price) VALUES (%s, %s, %s)"
cursor.executemany(insert_query_milk, milk_data)
#Other Important Tables
cursor.execute("""
CREATE TABLE cust (
cust_id INT PRIMARY KEY,
cust_name VARCHAR(50),
phone_no BIGINT,
email_id VARCHAR(50),
password VARCHAR(50),
pass_qn VARCHAR(255),
pass_ans VARCHAR(50)
)
""")
cursor.execute("""
CREATE TABLE order_info (
order_no INT PRIMARY KEY,
cust_id INT,
FOREIGN KEY (cust_id) REFERENCES cust (cust_id)
)
""")
cursor.execute("""
CREATE TABLE orders (
order_no INT,
item_no INT,
addon_no INT,
milk_no INT,
qty INT,
total_price INT,
FOREIGN KEY (order_no) REFERENCES order_info (order_no),
FOREIGN KEY (item_no) REFERENCES items (item_no),
FOREIGN KEY (addon_no) REFERENCES add_ons (addon_no),
FOREIGN KEY (milk_no) REFERENCES milk (milk_no)
)
""")
# Create the customer_review table
cursor.execute("""
CREATE TABLE customer_review (
id INT AUTO_INCREMENT PRIMARY KEY,
cust_id INT,
rating INT,
feedback TEXT,
reviewed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (cust_id) REFERENCES cust (cust_id)
)
""")
#End Message
print("Successfully Installed Pre-requisites")
mydb.commit()
mydb.close()