-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
123 lines (111 loc) · 4.34 KB
/
Copy pathschema.sql
File metadata and controls
123 lines (111 loc) · 4.34 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
123
-- ShopAI Database Schema
-- Run this file to setup the database
-- mysql -u root -p < schema.sql
CREATE DATABASE IF NOT EXISTS ecommerce_db;
USE ecommerce_db;
-- Users Table
CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
is_admin BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Categories Table
CREATE TABLE IF NOT EXISTS categories (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL UNIQUE,
icon VARCHAR(100) DEFAULT 'bi-tag',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Products Table
CREATE TABLE IF NOT EXISTS products (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(200) NOT NULL,
description TEXT,
price DECIMAL(10,2) NOT NULL,
category VARCHAR(100),
image_url VARCHAR(300),
stock INT DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Cart Table
CREATE TABLE IF NOT EXISTS cart (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
product_id INT,
quantity INT DEFAULT 1,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (product_id) REFERENCES products(id)
);
-- Orders Table
CREATE TABLE IF NOT EXISTS orders (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
total_amount DECIMAL(10,2),
status VARCHAR(50) DEFAULT 'pending',
fraud_risk_score FLOAT DEFAULT 0.0,
fraud_reasons TEXT DEFAULT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
);
-- Order Items Table
CREATE TABLE IF NOT EXISTS order_items (
id INT AUTO_INCREMENT PRIMARY KEY,
order_id INT,
product_id INT,
quantity INT,
price DECIMAL(10,2),
FOREIGN KEY (order_id) REFERENCES orders(id),
FOREIGN KEY (product_id) REFERENCES products(id)
);
-- Reviews Table
CREATE TABLE IF NOT EXISTS reviews (
id INT AUTO_INCREMENT PRIMARY KEY,
product_id INT,
user_id INT,
rating INT CHECK (rating BETWEEN 1 AND 5),
review_text TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (product_id) REFERENCES products(id),
FOREIGN KEY (user_id) REFERENCES users(id)
);
-- Wishlist Table
CREATE TABLE IF NOT EXISTS wishlist (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
product_id INT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (product_id) REFERENCES products(id),
UNIQUE KEY unique_wishlist (user_id, product_id)
);
-- User Activity Table (for AI Recommendations)
CREATE TABLE IF NOT EXISTS user_activity (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
product_id INT,
activity_type VARCHAR(50),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (product_id) REFERENCES products(id)
);
-- Sample Categories
INSERT INTO categories (name, icon) VALUES
('Electronics', 'bi-cpu'),
('Fashion', 'bi-bag'),
('Books', 'bi-book'),
('Accessories', 'bi-watch'),
('Home', 'bi-house'),
('Mobile', 'bi-phone'),
('Sports', 'bi-bicycle'),
('Gaming', 'bi-controller');
-- Sample Products
INSERT INTO products (name, description, price, category, image_url, stock) VALUES
('Wireless Headphones', 'Premium sound quality headphones with noise cancellation', 2499.00, 'Electronics', 'https://images.unsplash.com/photo-1505740420928-5e560c06d30e?w=400&h=300&fit=crop', 50),
('Running Shoes', 'Lightweight and comfortable running shoes for everyday use', 1999.00, 'Fashion', 'https://images.unsplash.com/photo-1542291026-7eec264c27ff?w=400&h=300&fit=crop', 30),
('Python Programming Book', 'Learn Python from scratch with practical examples', 599.00, 'Books', 'https://images.unsplash.com/photo-1544716278-ca5e3f4abd8c?w=400&h=300&fit=crop', 100),
('Backpack', 'Water resistant 40L backpack for travel and daily use', 1299.00, 'Accessories', 'https://images.unsplash.com/photo-1553062407-98eeb64c6a62?w=400&h=300&fit=crop', 20),
('Smart Watch', 'Fitness tracker with heart rate monitor and GPS', 3499.00, 'Electronics', 'https://images.unsplash.com/photo-1523275335684-37898b6baf30?w=400&h=300&fit=crop', 15),
('Desk Lamp', 'LED adjustable desk lamp with multiple brightness levels', 899.00, 'Home', 'https://images.unsplash.com/photo-1507473885765-e6ed057f782c?w=400&h=300&fit=crop', 40);