This repository contains the MySQL database schema for an online shopping system. The schema is designed to manage users, managers, products, categories, brands, orders, shopping carts, purchase history, comments, shipping information, and discounts.
You can also view the ER diagram on dbdiagram.io.
The schema includes the following tables:
Users
Managers
Categories
Brands
Products
Orders
ShippingInfo
OrderDetails
ShoppingCart
CartItems
PurchaseHistory
Comments
Discounts
ProductDiscounts
user_id
: Primary key, auto-incrementusername
: Unique, not nullpassword
: Not nullname
: Not nullemail
: Unique, not nullcontact_number
: Optionalstreet
: Optionalcity
: Optionalstate
: Optionalpostal_code
: Optionalcountry
: Optionalregistration_date
: Default to current timestamp
manager_id
: Primary key, auto-incrementusername
: Unique, not nullpassword
: Not nullemail
: Unique, not nullregistration_date
: Default to current timestamp
category_id
: Primary key, auto-incrementname
: Unique, not null
brand_id
: Primary key, auto-incrementname
: Unique, not nullstatus
: ENUM('active', 'inactive', 'old') DEFAULT 'active'
product_id
: Primary key, auto-incrementname
: Not nulldescription
: Optionalprice
: Not nullstock
: Not nullcategory_id
: Foreign key toCategories
brand_id
: Foreign key toBrands
created_at
: Default to current timestampstatus
: ENUM('active', 'inactive') DEFAULT 'active'
order_id
: Primary key, auto-incrementuser_id
: Foreign key toUsers
order_date
: Default to current timestampstatus
: ENUM('pending', 'processing', 'shipped', 'delivered', 'cancelled', 'returned'), not nulltotal_amount
: Not nullshipping_info_id
: Foreign key toShippingInfo
shipping_info_id
: Primary key, auto-incrementtracking_number
: Optionalcarrier
: Optionalshipping_date
: Optionaldelivery_date
: Optionalstatus
: ENUM('pending', 'shipped', 'delivered', 'returned'), default 'pending'
order_detail_id
: Primary key, auto-incrementorder_id
: Foreign key toOrders
product_id
: Foreign key toProducts
quantity
: Not nullprice
: Not null
cart_id
: Primary key, auto-incrementuser_id
: Foreign key toUsers
created_at
: Default to current timestampupdated_at
: Default to current timestamp
cart_item_id
: Primary key, auto-incrementcart_id
: Foreign key toShoppingCart
product_id
: Foreign key toProducts
quantity
: Not null
history_id
: Primary key, auto-incrementuser_id
: Foreign key toUsers
order_id
: Foreign key toOrders
purchase_date
: Default to current timestamp
comment_id
: Primary key, auto-incrementproduct_id
: Foreign key toProducts
user_id
: Foreign key toUsers
comment
: Not nullcomment_date
: Default to current timestampstatus
: ENUM('approved', 'inappropriate') DEFAULT 'approved'moderated_by
: Foreign key toManagers
discount_id
: Primary key, auto-incrementname
: Not nulldescription
: Optionaldiscount_percentage
: Not nullstart_date
: Optionalend_date
: Optional
product_discount_id
: Primary key, auto-incrementproduct_id
: Foreign key toProducts
discount_id
: Foreign key toDiscounts
-
Code
- Contains the database SQL code and two Python files:
DataGenerator.py
: Generates fake data for the database.SampleQueries.py
: Contains sample query functions and CLI for user and manager.
environment.yml
: File to set up the project environment with conda.
- Contains the database SQL code and two Python files:
-
Documents
- Contains project documentation in Persian.
-
Normalized ER Diagram
- Contains the normalized ER diagram designed for this database.
-
Sample Generated Data
- Contains sample data generated using the
DataGenerator.py
script.
- Contains sample data generated using the
-
Clone the repository:
git clone https://github.com/Kiarashmo/OnlineShopping_Database.git cd OnlineShopping_Database
-
Create the database and tables:
mysql -u <your_mysql_username> -p < SQL_Code.sql
-
Populate the database with sample data:
mysql -u <your_mysql_username> -p < Data.sql
-
Set up the project environment using conda for the python files:
conda env create -f environment.yml conda activate OnlineShopping
-
User Sign Up:
python SampleQueries.py user sign_up --username johndoe --password securepassword --name "John Doe" --email [email protected] --contact_number 123-456-7890 --street "123 Main St" --city Anytown --state Anystate --postal_code 12345 --country USA
-
User Login:
python SampleQueries.py user login --username johndoe --password securepassword
- After logging in as a user, you will be prompted to choose a query:
Choose a query: 1: Check brand availability 2: Check total spending in a month 3: List of user's orders 0: Exit
- After logging in as a user, you will be prompted to choose a query:
-
Manager Login:
python SampleQueries.py manager login --username admin --password adminpassword
- After logging in as a manager, you will be prompted to choose a query:
Choose a query: 1: Users with recent purchases 2: Total sales by category 3: Pending orders 4: Low stock products 5: High spending users 6: Add discount 7: Label comment inappropriate 8: Top selling products last month 9: Inactive brands and product count 10: Total discount by product last month 11: Custom query 0: Exit
- After logging in as a manager, you will be prompted to choose a query:
-
Add Manager:
python SampleQueries.py manager add_manager --username newmanager --password newmanagerpassword --email [email protected]
-
Custom Query:
python SampleQueries.py manager custom_query --query "SELECT * FROM Users"
Contributions are welcome! Please fork this repository and submit pull requests.
If you have any question feel free and email me: Kiarash Mokhtari
This project is licensed under the GENERAL PUBLIC License. See the LICENSE file for details.