-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.sql
More file actions
76 lines (70 loc) · 2.38 KB
/
database.sql
File metadata and controls
76 lines (70 loc) · 2.38 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
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
role ENUM('admin','user') DEFAULT 'user',
phone VARCHAR(20) NULL,
address VARCHAR(255) NULL,
gender ENUM('male','female','other') NULL,
avatar VARCHAR(255) NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO users (name, email, password, role)
VALUES (
'Admin',
'admin@gmail.com',
'$2y$10$SCjQW6bHGWE.dJhnZfr4ZuF3ELOB.l4c1OHMMwhEl3ZqqiFuSI7eK',
'admin'
);
CREATE TABLE products (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(150) NOT NULL,
brand VARCHAR(50) NOT NULL,
size INT NOT NULL,
resolution VARCHAR(20) NOT NULL,
panel VARCHAR(20) NOT NULL,
is_curved TINYINT(1) DEFAULT 0,
price INT NOT NULL,
image VARCHAR(255) NULL,
description TEXT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE orders (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NULL,
total_price INT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE order_items (
id INT AUTO_INCREMENT PRIMARY KEY,
order_id INT NOT NULL,
product_id INT NOT NULL,
product_name VARCHAR(150) NOT NULL,
price INT NOT NULL,
qty INT NOT NULL,
FOREIGN KEY (order_id) REFERENCES orders(id)
);
CREATE TABLE chat_conversations (
id INT AUTO_INCREMENT PRIMARY KEY,
session_token VARCHAR(64) NOT NULL UNIQUE,
visitor_name VARCHAR(120) NULL,
visitor_email VARCHAR(150) NULL,
status ENUM('bot','waiting','admin','closed') NOT NULL DEFAULT 'bot',
assigned_admin_id INT NULL,
last_message_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_chat_status_updated (status, updated_at),
INDEX idx_chat_last_message (last_message_at)
);
CREATE TABLE chat_messages (
id INT AUTO_INCREMENT PRIMARY KEY,
conversation_id INT NOT NULL,
sender_type ENUM('visitor','bot','admin','system') NOT NULL,
sender_name VARCHAR(120) NULL,
message TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (conversation_id) REFERENCES chat_conversations(id) ON DELETE CASCADE,
INDEX idx_chat_messages_conversation (conversation_id, id)
);