model User {
id:string,
name:string,
email:string,
username: string && unique,
password:string ,
profilePic:string,
description:string,
gender:Gender,
followers:Integer,
following:Integer,
posts:Post[],
likedPosts:string[],
savedPosts:string[],
privacyMode:AccountPrivacyMode
}
enum AccountPrivacyMode{
PUBLIC
PRIVATE
}
enum Gender{
MALE
FEMALE
PREFER_NOT_TO_SAY
}
model Post{
id:string,
url:string,
dateCreated:timestamp,
description:string,
likes:Integer,
comments:Comment[],
userId:string,
user:User // who created or uploaded this post
}
model Comment{
id:string,
postId:string,
replies: Comment[],
likes:Integer,
dateAdded:timestamp // it could be string I am not sure,
userId:string,
user:User, // who's post on which people are commenting
commenterId:string,
Commenter: User // who commented to the post
}
model Notification{
id:string,
type:NotificationType,
relatedUser:User,
relatedUserId:string,
notificationContent:string,
read:boolean,
time:timestamp
}
enum NotificationType{
FOLLOW,
LIKE,
COMMENT,
MENTION,
SUGGESTION
}
model Message{
id: string,
content:string,
fromUserId:string,
toUserId:string,
dateSend:timestamp,
dateReceived:timestamp,
status:MessageStatus
}
enum MessageStatus{
SEEN
UNSEEN
}
model Chat{
id:string,
fromUserId:string,
toUserId:string,
messages:Message[]
}
chatgpt conversion of above schema into prisma schema
// This is your Prisma schema file,
// learn more about it in the docs: <https://pris.ly/d/prisma-schema>
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: <https://pris.ly/cli/accelerate-init>
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id String @id @default(uuid())
name String
email String @unique
username String @unique
password String
profilePic String?
description String?
gender Gender?
followersCount Int @default(0)
followingCount Int @default(0)
followers Follower[] @relation("UserAsFollower")
following Follower[] @relation("UserAsFollowing")
posts Post[]
likedPosts String[]
savedPosts String[]
privacyMode AccountPrivacyMode?
notifications Notification[] @relation("UserNotifications")
comments Comment[] @relation("Commenter")
}
model Follower {
id String @id @default(uuid())
userId String
followerId String
user User @relation("UserAsFollower", fields: [userId], references: [id])
follower User @relation("UserAsFollowing", fields: [followerId], references: [id])
@@unique([userId, followerId]) // Prevent duplicate follower relationships
}
enum AccountPrivacyMode {
PUBLIC
PRIVATE
}
enum Gender {
MALE
FEMALE
PREFER_NOT_TO_SAY
}
model Post {
id String @id @default(uuid())
url String
dateCreated DateTime @default(now())
description String?
likes Int @default(0)
comments Comment[]
userId String
user User @relation(fields: [userId], references: [id])
}
model Comment {
id String @id @default(uuid())
text String
postId String
post Post @relation(fields: [postId], references: [id])
parentId String? // Optional for replies
parent Comment? @relation("CommentReplies", fields: [parentId], references: [id])
replies Comment[] @relation("CommentReplies")
likes Int @default(0)
dateAdded DateTime @default(now())
userId String
commenter User @relation("Commenter", fields: [userId], references: [id])
}
model Notification {
id String @id @default(uuid())
type NotificationType
forUserId String
forUser User @relation(fields: [forUserId], references: [id], name: "UserNotifications")
notificationContent String
read Boolean @default(false)
time DateTime @default(now())
}
enum NotificationType {
FOLLOW
LIKE
COMMENT
MENTION
SUGGESTION
}
enum Status {
OFFLINE
ONLINE
TYPING
}
model Message {
id String @id @default(uuid())
content String
fromUserId String
toUserId String
dateSend DateTime @default(now())
dateReceived DateTime?
status MessageStatus @default(UNSEEN)
chat Chat @relation(fields: [chatId], references: [id])
chatId String
}
enum MessageStatus {
SEEN
UNSEEN
}
model Chat {
id String @id @default(uuid())
fromUserId String
toUserId String
messages Message[]
@@unique([fromUserId, toUserId])
}