-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.sql
More file actions
110 lines (105 loc) · 3.46 KB
/
Copy pathDatabase.sql
File metadata and controls
110 lines (105 loc) · 3.46 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
CREATE database focusflow;
USE focusflow;
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL,
password VARCHAR(255) NOT NULL,
avatar VARCHAR(255)
);
CREATE TABLE songs (
id INT AUTO_INCREMENT PRIMARY KEY,
song_number INT NOT NULL,
song_name VARCHAR(255) NOT NULL,
duration VARCHAR(20) NOT NULL
);
ALTER TABLE songs
ADD COLUMN file_path VARCHAR(500) NOT NULL;
CREATE TABLE user_songs (
user_id INT NOT NULL,
song_id INT NOT NULL,
PRIMARY KEY (user_id, song_id),
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (song_id) REFERENCES songs(id) ON DELETE CASCADE
);
CREATE TABLE videos (
id INT AUTO_INCREMENT PRIMARY KEY,
file_name VARCHAR(255) NOT NULL,
file_path VARCHAR(500) NOT NULL,
user_id INT NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
ALTER TABLE songs ADD CONSTRAINT unique_song_path_per_user UNIQUE (file_path, id);
CREATE TABLE quotes (
id INT AUTO_INCREMENT PRIMARY KEY,
content TEXT NOT NULL,
author VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE task (
task_id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
title VARCHAR(100),
date DATE,
start_time TIME,
end_time TIME,
deadline DATETIME,
is_completed BOOLEAN DEFAULT FALSE,
reminded TINYINT(1) DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE note (
note_id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
content TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
task_id INT DEFAULT NULL,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (task_id) REFERENCES task(task_id) ON DELETE SET NULL
);
ALTER TABLE task ADD COLUMN remind_at DATETIME NULL;
CREATE TABLE study_time (
id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT NOT NULL,
study_date DATE NOT NULL,
hours DECIMAL(10, 8) NOT NULL);
CREATE TABLE friendships (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
friend_id INT NOT NULL,
status ENUM('pending', 'accepted', 'rejected') DEFAULT 'pending',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
UNIQUE KEY unique_friendship (user_id, friend_id),
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (friend_id) REFERENCES users(id) ON DELETE CASCADE
);
-- Bảng chat_conversations
CREATE TABLE chat_conversations (
chat_id INT AUTO_INCREMENT PRIMARY KEY,
is_group BOOLEAN,
chat_name VARCHAR(100),
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- Bảng chat_members
CREATE TABLE chat_members (
chat_id INT,
user_id INT,
joined_at DATETIME DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (chat_id, user_id),
FOREIGN KEY (chat_id) REFERENCES chat_conversations(chat_id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
-- Bảng chat_messages
CREATE TABLE chat_messages (
message_id INT AUTO_INCREMENT PRIMARY KEY,
chat_id INT,
sender_id INT,
content TEXT,
type ENUM('text', 'image', 'file', 'audio', 'emoji'),
file_path VARCHAR(255),
sent_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (chat_id) REFERENCES chat_conversations(chat_id) ON DELETE CASCADE,
FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE
);
ALTER TABLE chat_conversations ADD COLUMN group_name VARCHAR(255)