스키마 디자인 [DATABASE]

grapefruit·2022년 10월 6일
0

BE 2022.10.03~10.07

목록 보기
1/4
post-thumbnail

Database 설계

user : post = 1 : N
하나의 user는 여러개의 post를 작성 할 수 있다.
하나의 post는 하나의 유저만 작성할 수 있다.

user : comment = 1 : M
하나의 user는 여러개의 comment를 작성 할 수 있다.

post : comment = 1 : N
하나의 post에 여러개의 comment를 작성 할 수 있다.

post : hashtag = N : M
하나의 post는 여러개의 hashtag를 가질 수 있다.
하나의 hashtag는 여러개의 post에 달릴 수 있다.

post : post hashtag = N : M
하나의 post는 여러개의 post hashtag를 가질 수 있다.
하나의 post hashtag는 여러개의 post에 태그될 수 있다.

user : like = 1 : N
하나의 user는 여러개의(여러 포스트에) like를 할 수 있다.
하나의 like는 하나의 user(like를 한 주체)만 가질 수 있다.

post(또는 comment) : like = 1 : N
하나의 post(또는 comment)는 여러개의 like를 받을 수 있다.
하나의 like는 하나의 post(또는 comment)에만 보내질 수 있다.

user : following = N : M
하나의 user는 여러명을 following 할 수 있다.
하나의 following(된 대상)은 여러 user로부터 팔로잉 받을 수 있다.

Schema 작성

dbdiagram프로그램을 이용했다.

// dbdiagram

Table users {
  id int [pk, increment]
  name varchar
  password password
  }
  
  table posts {
    id int [pk]
    user_id int
    content varchar
    created_at timestamp [default: 'now()']
  }
  
  table comments {
    id int [pk]
    user_id int
    post_id int
    comment varchar
    created_at timestamp [default: 'now()']
  }
  
  table likes {
    id int [pk]
    user_id int
    post_id int
    created_at timestamp
  }
  
  table hashtags {
    id int [pk]
    post_id int
    hashtag_id int
  }
  
  table post_hashtag {
    post_id int
    hashtag_id int
  }
  
  table follow {
    id int [pk]
    name varchar
  }
  
  table following {
    user_id int
    follower_id int
  }
 Ref: "users"."id" < "follow"."id"
 Ref: "users"."id" < "following"."user_id"
 Ref: "users"."id" < "hashtags"."id"
 Ref: "users"."id" < "comments"."user_id"
 Ref: "users"."id" < "likes"."user_id"
 Ref: "users"."id" < "posts"."user_id"
 Ref: "posts"."id" < "likes"."post_id"
 Ref: "posts"."id" < "post_hashtag"."post_id"
 Ref: "posts"."id" < "hashtags"."post_id"
 Ref: "posts"."id" < "comments"."post_id"
 Ref: "follow"."id" < "following"."follower_id"
 Ref: "hashtags"."id" < "post_hashtag"."hashtag_id"

후기 :)

처음 해봤는데, 내가 스스로 해봤다는 그런 뿌듯함이 너무나 몰려오는 그런 느낌

그리고 어렵긴 어렵지만 그래도 재미가 있다는 느낌을 또 받아서 아주 기분이 좋다.

하지만 이해할 내용도 아직 많이 남았고, 이해를 다 한 것도 아니기에 겸손하게 다시

스스로 배워가야한다. 절대 자만하면 안된다!!!

profile
개발자몽

0개의 댓글