본문 바로가기

백엔드/Prisma + GraphQL

Prisma1과 Prisma2 데이터 모델링 비교

[인스타그램 클론코딩] Prisma2 데이터 모델링 포스트의 Prisma2 데이터 모델과 다음의 Prisma1 데이터 모델을 비교하면, Prisma1이 사용된 백앤드에 Prisma2를 적용하기 쉬울겁니다.

Prisma1

Prisma2 데이터 모델과 동일한 구조입니다.

type User {
  id: ID! @id
  userName: String! @unique
  avatar: String @default(value: "https://3.bp.blogspot.com/-qtEejOg1NHA/Xobmg2y_QeI/AAAAAAAAIVE/UFKPvpeHjKUqCEFOX8lT4MsKz-PwpEGJgCLcBGAsYHQ/s1600/default_user.png")
  email: String! @unique
  firstName: String @default(value: "")
  lastName: String
  bio: String
  posts: [Post!] @relation(name: "PostsOfUser", onDelete: CASCADE)
  following: [User!] @relation(name: "FollowRelation")
  followers: [User!] @relation(name: "FollowRelation")
  likes: [Like!] @relation(name: "LikesOfUser", onDelete: CASCADE)
  comments: [Comment!] @relation(name: "CommentsOfUser", onDelete: CASCADE)
  rooms: [Room!]
  createdAt: DateTime! @createdAt
  updatedAt: DateTime! @updatedAt
}

type Post {
  id: ID! @id
  files: [File!]! @relation(name: "FilesOfPost", onDelete: CASCADE)
  location: String
  user: User! @relation(name: "PostsOfUser")
  caption: String!
  likes: [Like!]! @relation(name: "LikesOfPost", onDelete: CASCADE)
  comments: [Comment!]! @relation(name: "CommentsOfPost", onDelete: CASCADE)
  createdAt: DateTime! @createdAt
  updatedAt: DateTime! @updatedAt
}

type Like {
  id: ID! @id
  user: User! @relation(name: "LikesOfUser")
  post: Post @relation(name: "LikesOfPost")
}

type Comment {
  id: ID! @id
  text: String!
  user: User! @relation(name: "CommentsOfUser")
  post: Post @relation(name: "CommentsOfPost")
  createdAt: DateTime! @createdAt
  updatedAt: DateTime! @updatedAt
}

type File {
  id: ID! @id
  url: String!
  post: Post @relation(name: "FilesOfPost")
  createdAt: DateTime! @createdAt
  updatedAt: DateTime! @updatedAt
}