Skip to content

Commit 600d69d

Browse files
committed
feat: database design
1 parent ad6f8e5 commit 600d69d

File tree

2 files changed

+288
-168
lines changed

2 files changed

+288
-168
lines changed

docs/database.md

Lines changed: 127 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,132 @@
11
# Database design
22

3+
## Table design
4+
5+
- User can create many Groups, Group can have many Users
6+
- User can be Editor, Moderator, Admin
7+
- User can create many Posts, Post can have many Comments and Images
8+
- User can create Comments on Posts
9+
- User can like, share, up vote, down vote a Post
10+
- User can Tag a Post
11+
- Tag have two type: Tag or Category
12+
- Tag can have many Images
13+
- Comments can be nested
14+
- Tag can be nested (Child & Parent relationship)
15+
- User can like, share, up vote, down vote, book mark, pin a Post
16+
- User can like, share, up vote, down vote a Comment
17+
- User can follow/unfollow other users
18+
- User can follow/unfollow a tag
19+
- Post can be STANDARD, ASIDE, GALLERY, LINK, IMAGE, QUOTE, STATUS, VIDEO, AUDIO, POLL
20+
- Post's status can be: DRAFT, PUBLISHED, ARCHIVED, TRASHED, BLOCKED
21+
- User's status can be: UNVERIFIED, VERIFIED, BLOCKED
22+
23+
324
```mermaid
425
erDiagram
5-
Post ||--o{ Comment : has
6-
Post ||--o{ TagOnPost : has
7-
Post ||--o{ PostOnUser : has
8-
User ||--o{ Post : creates
9-
User ||--o{ Comment : writes
10-
User ||--o{ PostOnUser : interacts
11-
User ||--o{ TagOnPost : tags
12-
Comment ||--o{ CommentOnUser : interacts
13-
Tag ||--o{ TagOnPost : has
14-
Image ||--o{ Post : contains
15-
Image ||--o{ Tag : contains
26+
User {
27+
String id PK
28+
String name
29+
String email UK
30+
String username UK
31+
String bio
32+
String password
33+
UserStatus userStatus
34+
}
35+
36+
Group {
37+
String id PK
38+
String name UK
39+
String description
40+
String ownerId FK
41+
DateTime createdAt
42+
DateTime updatedAt
43+
DateTime deletedAt
44+
}
45+
46+
UserOnGroup {
47+
String userId FK
48+
String groupId FK
49+
GroupRole role
50+
}
51+
52+
Post {
53+
String id PK
54+
String title
55+
String content
56+
PostStatus postStatus
57+
String authorId FK
58+
DateTime createdAt
59+
DateTime updatedAt
60+
DateTime deletedAt
61+
}
62+
63+
Comment {
64+
String id PK
65+
String content
66+
String authorId FK
67+
String commentOnPostId FK
68+
String parentCommentId FK
69+
DateTime createdAt
70+
DateTime updatedAt
71+
DateTime deletedAt
72+
}
73+
74+
Tag {
75+
String id PK
76+
String name UK
77+
TagType type
78+
String parentTagId FK
79+
}
80+
81+
Media {
82+
String id PK
83+
String path
84+
String name
85+
Int width
86+
Int height
87+
String format
88+
String previewUrl
89+
String caption
90+
String url
91+
String mime
92+
String userId FK
93+
}
94+
95+
Account {
96+
String id PK
97+
String userId FK
98+
String provider
99+
String providerAccountId UK
100+
String refresh_token
101+
String access_token
102+
Int expires_at
103+
}
104+
105+
Session {
106+
String id PK
107+
String sessionToken UK
108+
String userId FK
109+
DateTime expires
110+
}
111+
112+
User ||--o{ Group : "creates"
113+
User ||--o{ UserOnGroup : "joins"
114+
Group ||--o{ UserOnGroup : "has"
115+
User ||--o{ Post : "writes"
116+
User ||--o{ Comment : "writes"
117+
Post ||--o{ Comment : "has"
118+
User ||--o{ PostOnUser : "interacts"
119+
Post ||--o{ PostOnUser : "receives"
120+
User ||--o{ CommentOnUser : "interacts"
121+
Comment ||--o{ CommentOnUser : "receives"
122+
User ||--o{ Follower : "follows"
123+
User ||--o{ Account : "has"
124+
User ||--o{ Session : "has"
125+
Post ||--o{ TagOnPost : "tagged_with"
126+
Tag ||--o{ TagOnPost : "tags"
127+
Tag ||--o{ UserOnTag : "followed_by"
128+
User ||--o{ UserOnTag : "follows"
129+
User ||--o{ Media : "uploads"
130+
Post ||--o{ Media : "contains"
131+
Tag ||--o{ Media : "has"
16132
```

0 commit comments

Comments
 (0)