-
Notifications
You must be signed in to change notification settings - Fork 47
/
fruit_shop_schema.py
79 lines (70 loc) · 1.87 KB
/
fruit_shop_schema.py
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
tab_fruits = """
CREATE TABLE fruits (
fruit_id INTEGER PRIMARY KEY AUTO_INCREMENT,
fruit_name TEXT NOT NULL,
selling_price REAL,
stock_quantity INTEGER,
fruit_type TEXT,
shelf_life INTEGER
);
"""
tab_customers = """
CREATE TABLE customers (
customer_id INTEGER PRIMARY KEY AUTO_INCREMENT,
first_name TEXT,
last_name TEXT,
phone_number TEXT,
email TEXT
);
"""
tab_suppliers = """
CREATE TABLE suppliers (
supplier_id INTEGER PRIMARY KEY AUTO_INCREMENT,
supplier_name TEXT NOT NULL,
contact_number TEXT,
email TEXT
);
"""
tab_sales = """
CREATE TABLE sales (
sale_id INTEGER PRIMARY KEY AUTO_INCREMENT,
customer_id INTEGER,
sale_date DATE,
total_price REAL,
FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
);
"""
tab_sale_items = """
CREATE TABLE sale_items (
sale_item_id INTEGER PRIMARY KEY AUTO_INCREMENT,
sale_id INTEGER NOT NULL,
fruit_id INTEGER NOT NULL,
quantity_sold INTEGER,
price_per_item REAL,
item_total_price REAL,
FOREIGN KEY (sale_id) REFERENCES sales(sale_id),
FOREIGN KEY (fruit_id) REFERENCES fruits(fruit_id)
);
"""
tab_purchases = """
CREATE TABLE purchases (
purchase_id INTEGER PRIMARY KEY AUTO_INCREMENT,
supplier_id INTEGER NOT NULL,
purchase_date DATE,
total_cost REAL,
FOREIGN KEY (supplier_id) REFERENCES suppliers(supplier_id)
);
"""
tab_purchase_items = """
CREATE TABLE purchase_items (
purchase_item_id INTEGER PRIMARY KEY AUTO_INCREMENT,
purchase_id INTEGER NOT NULL,
fruit_id INTEGER NOT NULL,
quantity_purchased INTEGER,
cost_per_item REAL,
item_total_cost REAL,
FOREIGN KEY (purchase_id) REFERENCES purchases(purchase_id),
FOREIGN KEY (fruit_id) REFERENCES fruits(fruit_id)
);
"""
tables = [tab_fruits, tab_customers, tab_suppliers, tab_sales, tab_sale_items, tab_purchases, tab_purchase_items]