Skip to content

Commit ad6f8e5

Browse files
committed
feat: update database
1 parent ede0a24 commit ad6f8e5

File tree

6 files changed

+39
-31
lines changed

6 files changed

+39
-31
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ turbo dev
6565

6666
# Folder structure
6767

68-
6968
## Front side functions
7069

7170
- [x] Register by email or github
@@ -92,4 +91,4 @@ turbo dev
9291
- [ ] Manage posts
9392
- [ ] Manage images
9493
- [ ] Settings: Header/Menu
95-
- [ ] Manage roles and permission
94+
- [ ] Manage roles and permission

apps/web/.env.example

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,3 @@ JWT_SECRET=
1111
NEXT_PUBLIC_FB_APP_ID=
1212

1313
RESEND_AUDIENCE_ID=
14-
15-
DATABASE_URL=

docs/database.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Database design
2+
3+
```mermaid
4+
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
16+
```

packages/database/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
55
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
66

7-
DATABASE_URL=
7+
# DATABASE_URL=postgresql://localhost:5432/postgres?user=postgres&password=example

packages/database/prisma/schema.prisma

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ model PostMetaData {
7979
author User @relation(fields: [authorId], references: [id])
8080
}
8181

82+
enum SocialProvider {
83+
TWITTER
84+
FACEBOOK
85+
GITHUB
86+
YOUTUBE
87+
LINKEDIN
88+
INSTAGRAM
89+
}
90+
8291
model User {
8392
id String @id @default(cuid())
8493
name String?
@@ -91,12 +100,8 @@ model User {
91100
website String?
92101
address String?
93102
phone String?
94-
twitter String?
95-
facebook String?
96-
github String?
97-
youtube String?
98-
linkedin String?
99-
instagram String?
103+
socialProvider SocialProvider?
104+
socialId String?
100105
totalFollower Int @default(0)
101106
totalFollowing Int @default(0)
102107
totalPost Int @default(0)
@@ -106,7 +111,6 @@ model User {
106111
updatedAt DateTime @updatedAt
107112
accounts Account[]
108113
comment Comment[]
109-
commentOnUser CommentOnUser[]
110114
followers Follower[] @relation("follower")
111115
followings Follower[] @relation("following")
112116
images Image[]
@@ -158,29 +162,16 @@ model Tag {
158162
}
159163

160164
model Comment {
161-
id String @id @default(cuid())
162-
createdAt DateTime @default(now())
163-
updatedAt DateTime @updatedAt
165+
id String @id @default(cuid())
166+
createdAt DateTime @default(now())
167+
updatedAt DateTime @updatedAt
164168
content String?
165169
authorId String
166170
parentCommentId String?
167-
pinned Boolean @default(false)
171+
pinned Boolean @default(false)
168172
commentOnPostId String
169-
author User @relation(fields: [authorId], references: [id])
170-
commentOnPost Post @relation(fields: [commentOnPostId], references: [id])
171-
commentOnUser CommentOnUser[]
172-
}
173-
174-
model CommentOnUser {
175-
createdAt DateTime @default(now())
176-
updatedAt DateTime @updatedAt
177-
userId String
178-
commentId String
179-
type CommentOnUserType @default(LIKE)
180-
comment Comment @relation(fields: [commentId], references: [id])
181-
user User @relation(fields: [userId], references: [id])
182-
183-
@@id([userId, commentId])
173+
author User @relation(fields: [authorId], references: [id])
174+
commentOnPost Post @relation(fields: [commentOnPostId], references: [id])
184175
}
185176

186177
model Account {
@@ -280,6 +271,7 @@ enum PostStatus {
280271
}
281272

282273
enum PostOnUserType {
274+
COMMENT
283275
LIKE
284276
FAVORITE
285277
FOLLOW

packages/database/src/posts/queries.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"use server"
22

3+
import { log } from "console"
4+
35
import { PostStatus, Prisma } from "@prisma/client"
46
import dayjs from "dayjs"
57
import slugify from "slugify"
@@ -164,6 +166,7 @@ export const getPosts = async (searchParams: TGetPostsRequest): Promise<TGetPost
164166
},
165167
}
166168
} catch (error) {
169+
console.log(error)
167170
return {
168171
data: {
169172
data: [],

0 commit comments

Comments
 (0)