-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbDiagram.txt
More file actions
84 lines (75 loc) · 2.63 KB
/
Copy pathdbDiagram.txt
File metadata and controls
84 lines (75 loc) · 2.63 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
// 📘 Chat App Database Diagram
// ✅ Compatible with dbdiagram.io (no syntax errors)
Table users {
_id ObjectId [pk]
firstName string [not null]
lastName string [not null]
displayName string [not null, note: 'Tên hiển thị']
username string [unique, not null, note: 'Dùng để đăng nhập']
password string [not null, note: 'Đã mã hoá (bcrypt)']
phone string
dob date
avatar string
bio string
friends ObjectId[] [ref: > users._id, note: 'Danh sách bạn bè']
createdAt datetime [default: "CURRENT_TIMESTAMP"]
updatedAt datetime [default: "CURRENT_TIMESTAMP"]
}
Table refresh_tokens {
_id ObjectId [pk]
userId ObjectId [ref: > users._id, not null]
token string [not null, note: 'Refresh token (đã hash)']
expiresAt datetime [not null]
revoked boolean [default: false]
replacedBy string
createdAt datetime [default: "CURRENT_TIMESTAMP"]
updatedAt datetime [default: "CURRENT_TIMESTAMP"]
}
Table friend_requests {
_id ObjectId [pk]
fromUserId ObjectId [ref: > users._id, not null]
toUserId ObjectId [ref: > users._id, not null]
status string [not null, note: 'pending | accepted | declined | cancelled']
message string
createdAt datetime [default: "CURRENT_TIMESTAMP"]
updatedAt datetime [default: "CURRENT_TIMESTAMP"]
}
Table conversations {
_id ObjectId [pk]
type string [not null, note: 'direct | group']
name string
members ObjectId[] [ref: > users._id]
admins ObjectId[] [ref: > users._id]
lastMessageId ObjectId [ref: > messages._id, note: 'Tin nhắn cuối cùng']
createdAt datetime [default: "CURRENT_TIMESTAMP"]
updatedAt datetime [default: "CURRENT_TIMESTAMP"]
}
Table messages {
_id ObjectId [pk]
conversationId ObjectId [ref: > conversations._id, not null]
senderId ObjectId [ref: > users._id, not null]
text string
attachments json [note: 'Danh sách file/hình gửi kèm']
readBy ObjectId[] [ref: > users._id]
createdAt datetime [default: "CURRENT_TIMESTAMP"]
updatedAt datetime [default: "CURRENT_TIMESTAMP"]
}
Table conversation_members {
_id ObjectId [pk]
conversationId ObjectId [ref: > conversations._id, not null]
userId ObjectId [ref: > users._id, not null]
role string [default: "member", note: 'member | admin']
lastReadAt datetime
mutedUntil datetime
joinedAt datetime [default: "CURRENT_TIMESTAMP"]
}
Table notifications {
_id ObjectId [pk]
userId ObjectId [ref: > users._id, not null]
type string [note: 'friend_request | message | system']
referenceId ObjectId [note: 'ID liên quan (request/message/...)']
title string
body string
isRead boolean [default: false]
createdAt datetime [default: "CURRENT_TIMESTAMP"]
}