Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

karrot-0009: DB 설계 #17

Open
hello-yoochul opened this issue Apr 16, 2023 · 9 comments
Open

karrot-0009: DB 설계 #17

hello-yoochul opened this issue Apr 16, 2023 · 9 comments
Assignees
Labels
Analysis Doc Improvements or additions to documentation

Comments

@hello-yoochul
Copy link
Contributor

hello-yoochul commented Apr 16, 2023

채팅, 알림, 거래

  • 테이블
    • chat_room (채팅방)
      • id bigint, (PK)
      • product_id bigint NOT NULL,
      • potential_buyer_id bigint NOT NULL,
      • created_at timestamp with time zone NOT NULL,
        • Q. 시간에 timezone 추가해야 되나?
    • chat_room_message (채팅방 메시지)
      • id bigint, (PK)
      • chat_room_id bigint NOT NULL,
      • receiver_id bigint NOT NULL,
    • block_user (차단하기) - "당근마켓에서 차단을 하면 서로의 게시물을 볼 수 없으며 채팅도 불가능합니다."
      • origin_id bigint, (PK)
      • target_id bigint, (PK)
      • created_at timestamp with time zone NOT NULL,
        • Q. 시간에 timezone 추가해야 되나?
    • trade_review (거래후기)
      • id bigint,
      • seller_id bigint NOT NULL,
      • buyer_id bigint NOT NULL,
      • product_id bigint NOT NULL,
      • message text NOT NULL,
      • created_at timestamp with time zone NOT NULL,
        • Q. 시간에 timezone 추가해야 되나?
      • rating smallint NOT NULL GENERATED ALWAYS AS IDENTITY ( MINVALUE 1 MAXVALUE 5 ),
    • product_price_offer (가격제안)
      • product_id bigint,
      • sender_id bigint,
      • offer_price money,
      • accepted_or_not boolean,
      • created_at timestamp with time zone
      • PRIMARY KEY (sender_id, product_id)
  • 궁금했던 점
  • 내파트 이외 추가 찾아본 자료

알림은 푸시 알림 설계 분석 이슈에서 DB 명확해질 예정

@hello-yoochul hello-yoochul added Doc Improvements or additions to documentation Analysis labels Apr 16, 2023
@tae0y
Copy link
Contributor

tae0y commented Apr 16, 2023

사용자 부분

  1. 쿼리 변환 온라인툴 사용해서 mysql 쿼리를 postgresql로 변환, 칼럼 데이터타입은 직접 DB올리면서 조정 필요
    http://www.sqlines.com/online
  2. 여러 시스템에 걸쳐 유일해야하거나, 또는 다음 값을 유추하기 어려워야 하는 경우 UUID를 사용하면 좋겠음
  3. 그외 특이사항 없음

해야할일

  • ERD 이미지
  • CREATE구문
  • 토의한내용들 정리
  • 참고) 알림/채팅 부분은 아직 설계 진행중임

@tae0y tae0y self-assigned this Apr 16, 2023
@HiSeoYoon
Copy link
Contributor

goods
price_get_offer(boolean) - 판매 가격을 조정 여부 컬럼 추가

follow_category
사용자가 검색 시 사용할 카테고리를 사용자별로 등록하도록 테이블 추가
user_id (user 테이블 외래키)
categoty_id (categories 테이블 외래키)
is_use (boolean)

goods_images
upload_order (int4) - 사진을 등록한 순서를 등록하도록 컬럼 추가
is_thumbnail (boolean) - 썸네일이 저장되어있는지 확인하는 컬럼 추가

@tae0y
Copy link
Contributor

tae0y commented Apr 22, 2023

DB설계

  • 원하는 기능
    • 공동편집, 쿼리 ↔︎ ERD 다이어그램
    • postgre, mongodb 지원
  • 이렇게 하고싶음: 로컬 도커에 DB를 띄우고, pgadmin으로 erd 다이어그램 보기
    • DB설계는 쿼리로 하면서, 중간중간 pgadmin 들어가서 erd 참고하며 진행
    • DDL쿼리를 프로젝트 파일에 포함시켜서 깃헙으로 내용공유/공동편집
  • 왜 그러냐면...
    • erdcloud가 가장 좋지만, postgre를 지원하지 않음
    • 그외 온라인 ERD툴이 여러가지 있지만, 무료로 잠깐 사용할 수 있는 툴은 별로 없음
    • 로컬 도커에 postgre db를 띄우고 pgadmin으로 erd 다이어그램을 보기만 해야할듯
    • mongo db도 로컬에서 erd 다이어그램 보는방법 고민중

DB테스트

  • 운영 DB는 postgre/mongDB인데, 테스트할때는 h2 DB를 사용하고 있음
  • 도커를 사용해서 테스트할때도 postgre/mongoDB를 사용하면 좋겠음
    -> 특정 DB에 종속적인 코드를 짤 경우에 테스트하기 편함
    -> 굳이~~ 로컬 테스트 단계에서 H2인메모리 대신 반드시 도커를 사용해야할 이유는 없지만
    -> 그렇다고 굳이~~ 도커를 사용할 수 있는데 H2인메모리 DB를 써야할 이유도 없음

@tae0y
Copy link
Contributor

tae0y commented Apr 22, 2023

  • 결론, 테스트DB에서도 postgresql 사용을 위해서 docker compose로 해보면 좋겠다

  • H2와 docker compose 테스트환경 비교

  • H2의 장점

    • 인메모리 DB로 외부 영향없이 완벽하게 독립적인 데이터로 테스트가능하다
    • 다른 DB 서비스 동작여부에 영향을 받지 않는다(외부 DB커넥션이 없음, 완전히 어플리케이션에만 집중)
    • 원하는 테스트 데이터를 마음대로 구성할 수 있고, 수행후 롤백이 필요 없으며, 빠르다!!!
  • H2의 단점

    • 개발사항에 따라 스키마 초기 구성을 최신화 해줘야한다
    • 프로젝트가 커지면 초기화해줘야할 테스트 데이터 양이 많아질 수 있다
      • DDL쿼리 및 초기화 데이터 쿼리는 깃을 사용해서 관리하면 좋다
    • 실제 쿼리 수행과 완벽하게 동일하지 않을 수 있다 (H2 <> postgresql/mongodb)
  • docker compose의 장/단점

    • 기본적으로 H2와 장/단점이 비슷하다
    • 다만, 도커의 경우 실제 쿼리 수행과 일치한다는 점이 장점이고 (docker compose에 설정만 해주면 된다)
    • CI 서버에서 사용하면 메모리 사용량에 주의해야 한다
    • 설정이 복잡할 수 있지만, testcontainer 라이브러리를 사용해 커버할 수 있다
  • 참고한 글들

@tae0y
Copy link
Contributor

tae0y commented Apr 22, 2023

잘모르겠는것: 테스트용 어노테이션들 차이점

jpatest
springtest

@tae0y
Copy link
Contributor

tae0y commented Apr 23, 2023

첫 postgresql erd 이미지, 업데이트후 readme에 추가
image

@tae0y
Copy link
Contributor

tae0y commented Apr 23, 2023

image

@HiSeoYoon 제안주신 내용 다 반영되어 있어요
@hello-yoochul 제안해준것 중에 아래 내용 제외했어요 확인해보시고 필요하면 다시 추가해주세요

  • chat_room_message (채팅방 메시지) / receiver_id → chat_room에서 받는사람 id를 알 수 있음
  • trade_review (거래후기) / seller_id → goods에서 파는사람 id 알 수 있음
  • product_price_offer (가격제안) / seller_id → goods에서 파는사람 id 알 수 있음

tae0y added a commit that referenced this issue Apr 23, 2023
tae0y added a commit that referenced this issue Apr 23, 2023
tae0y added a commit that referenced this issue Apr 29, 2023
@tae0y
Copy link
Contributor

tae0y commented Apr 30, 2023

  • postgis 패키지 설치된 이미지 사용하기
  • ddl쿼리 경로 설정해주기

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Analysis Doc Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants