Entity Relationship Diagram - hyeonwoody/hyeonworld GitHub Wiki

erDiagram
	user{
		bigint id PK "์œ ์ € id"
		bool login UK "๋กœ๊ทธ์ธ ์—ฌ๋ถ€"
		string(20) name UK "์„ฑํ•จ"
		int relation UK "์ดŒ์ˆ˜"
		int party_type UK "๊ฐ€์กฑ ๊ด€๊ณ„"
		string email "์ด๋ฉ”์ผ"
		bool proposition "์„ฑํ•จ ์ฃผ๊ฒฉ์กฐ์‚ฌ 0 : ์€ ์ด, 1 : ๋Š” ๊ฐ€" 
		string nick_name "์• ์นญ"
		bool nick_name_proposition "์• ์นญ ์ฃผ๊ฒฉ์กฐ์‚ฌ"
		bool in_game "๊ฒŒ์ž„ ์ฐธ๊ฐ€ ์—ฌ๋ถ€"
	}
	party{
		bigint id PK "ํŒŒํ‹ฐ id"
		int party_type "๊ฐ€์กฑ ๊ด€๊ณ„"
		datetime created_at "์ƒ์„ฑ ์‹œ๊ฐ„"
	}
	party_dashboard{
		bigint party_id FK "ํŒŒํ‹ฐ id"
		bigint current_game_id FK "ํ˜„์žฌ ๊ฒŒ์ž„"
		int current_game_stage "ํ˜„์žฌ ๊ฒŒ์ž„ ๋‹จ๊ณ„"
	}
	game{
		bigint id PK "๊ฒŒ์ž„ id"
		string name "๊ฒŒ์ž„ ์ด๋ฆ„"
		string description "๊ฒŒ์ž„ ์„ค๋ช…"
		bool playable "ํ”Œ๋ ˆ์ด ๊ฐ€๋Šฅ ์—ฌ๋ถ€"
	}
	round{
		bigint party_id FK "ํŒŒํ‹ฐ id"
		bigint id PK "๋ผ์šด๋“œ id"
		bigint game_id FK "๊ฒŒ์ž„ id"
		int answer "์ •๋‹ต"
		datetime created_at "์ƒ์„ฑ ์‹œ๊ฐ„"
	}
	submission{
		bigint id PK "์ œ์ถœ id"
		bigint round_id UK "๋ผ์šด๋“œ id"
		bigint user_id FK "์œ ์ € id"
		bigint number "์ˆซ์ž"
		string text "๊ธ€์ž"
	}
	score{
		bigint party_id FK "ํŒŒํ‹ฐ id ๋ณตํ•ฉํ‚ค"
		bigint user_id FK "์œ ์ € id ๋ณตํ•ฉํ‚ค"
		bigint score "์ข…ํ•ฉ ์ ์ˆ˜"
	}
	score_history{
		bigint user_id FK "์œ ์ € id"
		bigint party_id FK "ํŒŒํ‹ฐ id"
		bigint round_id FK "๋ผ์šด๋“œ id"
		bigint score "๋ผ์šด๋“œ ๋ณ„ ํš๋“ ์ ์ˆ˜"
	}
	party ||--|| party_dashboard : contains
	party_dashboard ||--|| game : "tracks current"
	party ||--o{ round : includes
	user ||--o{ submission : submits
	round ||--o{ submission : "is accosiated with"
	round ||--o{ score_history : generates
	score ||--o{ score_history : "is detailed in"
	
	game ||--|| round : "plays in"

ERD ๊ตฌ์กฐ

user: ์‚ฌ์šฉ์ž ์ •๋ณด
party: ๊ฒŒ์ž„ ํŒŒํ‹ฐ ์ •๋ณด
party_dashboard: ํ˜„์žฌ ํŒŒํ‹ฐ ์ƒํƒœ
round: ๊ฒŒ์ž„ ๋ผ์šด๋“œ ์ •๋ณด
game: ๊ฒŒ์ž„ ์ •๋ณด
submission: ์‚ฌ์šฉ์ž ์ œ์ถœ ์ •๋ณด
score: ์‚ฌ์šฉ์ž ์ ์ˆ˜
score_history: ๋ผ์šด๋“œ๋ณ„ ์ ์ˆ˜ ๊ธฐ๋ก

์ฃผ์š” ๊ด€๊ณ„

user

  • user์™€ submission: 1:N ๊ด€๊ณ„ ("submits")

party

  • party์™€ party_dashboard: 1:1 ๊ด€๊ณ„ ("contains")
  • party์™€ round: 1:N ๊ด€๊ณ„ ("includes")

round

  • round์™€ submission: 1:N ๊ด€๊ณ„ ("is associated with")
  • round์™€ score_history: 1:N ๊ด€๊ณ„ ("generates")

game

  • game๊ณผ round: 1:1 ๊ด€๊ณ„ ("plays in")
  • party_dashboard์™€ game: 1:1 ๊ด€๊ณ„ ("tracks current")

๋…ผ๋ฆฌ์  ์™ธ๋ž˜ํ‚ค

MSA๋กœ์˜ ํ™•์žฅ์„ฑ์„ ๊ณ ๋ คํ•˜์—ฌ ๋„๋ฉ”์ธ ๊ฐ„ ๊ฒฐํ•ฉ์„ ์ค„์ด๊ธฐ ์œ„ํ•ด
๋…ผ๋ฆฌ์  ์™ธ๋ž˜ํ‚ค๋งŒ ์‚ฌ์šฉํ•˜๊ณ  ๋ฌผ๋ฆฌ์  ์™ธ๋ž˜ํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

์žฅ์ :
์„œ๋น„์Šค ์ž์œจ์„ฑ ์ฆ๊ฐ€: ๊ฐ ์„œ๋น„์Šค๊ฐ€ ์ž์ฒด ๋ฐ์ดํ„ฐ ๋ชจ๋ธ์„ ์™„์ „ํžˆ ์ œ์–ดํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๋ฐฐํฌ ์šฉ์ด์„ฑ: ์„œ๋น„์Šค ๊ฐ„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ข…์†์„ฑ์ด ์ค„์–ด ๋…๋ฆฝ์ ์ธ ๋ฐฐํฌ๊ฐ€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
์„ฑ๋Šฅ ์ตœ์ ํ™”: ๊ฐ ์„œ๋น„์Šค์— ๋งž๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๊ธฐ์ˆ  ์„ ํƒ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

๋‹จ์ :
๋ฐ์ดํ„ฐ ์ผ๊ด€์„ฑ ๊ด€๋ฆฌ ๋ณต์žก: ์„œ๋น„์Šค ๊ฐ„ ๋ฐ์ดํ„ฐ ์ผ๊ด€์„ฑ์„ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋กœ์ง์œผ๋กœ ๊ด€๋ฆฌํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
์ฟผ๋ฆฌ ๋ณต์žก์„ฑ ์ฆ๊ฐ€: ์—ฌ๋Ÿฌ ์„œ๋น„์Šค์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์กฐํ•ฉํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ ์ฟผ๋ฆฌ๊ฐ€ ๋ณต์žกํ•ด์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๋ฐ์ดํ„ฐ ์ค‘๋ณต: ์ผ๋ถ€ ๋ฐ์ดํ„ฐ๊ฐ€ ์—ฌ๋Ÿฌ ์„œ๋น„์Šค์— ์ค‘๋ณต ์ €์žฅ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

score ๋ณตํ•ฉํ‚ค

์™ธ๋ž˜ํ‚ค๊ฐ€ ์•„๋‹Œ ์ด์œ 

  • MSA ์›์น™ ์ค€์ˆ˜:
    ๋…ผ๋ฆฌ์  ์™ธ๋ž˜ ํ‚ค ์‚ฌ์šฉ์œผ๋กœ ์„œ๋น„์Šค ๊ฐ„ ๊ฒฐํ•ฉ๋„๋ฅผ ๋‚ฎ์ถ”๊ณ  ๋…๋ฆฝ์„ฑ์„ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค.

UNIQUE๊ฐ€ ์•„๋‹Œ ์ด์œ 

  • ๋ฐ์ดํ„ฐ ๋ฌด๊ฒฐ์„ฑ:
    ๋ณตํ•ฉํ‚ค๋Š” NULL๊ฐ’์„ ํ—ˆ์šฉํ•˜์ง€ ์•Š๊ณ  UNIQUE๋Š” NULL๊ฐ’์„ ํ—ˆ์šฉํ•˜๋Š”๋ฐ
    party_id์™€ user_id๋Š” ํ•ญ์ƒ ์กด์žฌํ•˜๋ฏ€๋กœ ๋ณตํ•ฉํ‚ค๋กœ ๋ฐ์ดํ„ฐ ๋ฌด๊ฒฐ์„ฑ์„ ๋ณด์žฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ํด๋Ÿฌ์Šคํ„ฐ๋“œ ์ธ๋ฑ์Šค
    ๋ณตํ•ฉํ‚ค๋Š” ํด๋Ÿฌ์Šคํ„ฐ๋“œ ์ธ๋ฑ์Šค๊ฐ€ ์ƒ์„ฑ๋˜๊ณ 
    UNIQUE๋Š” ๋น„ํด๋Ÿฌ์Šคํ„ฐ๋“œ ์ธ๋ฑ์Šค๊ฐ€ ์ƒ์„ฑ ๋ฉ๋‹ˆ๋‹ค.
    ํด๋Ÿฌ์Šคํ„ฐ๋“œ ์ธ๋ฑ์Šค๋Š” ๋ฒ”์œ„ ๊ฒ€์ƒ‰๊ณผ ์—ฐ์†๋œ ๋ฐ์ดํ„ฐ๋ฅผ ๋น ๋ฅด๊ฒŒ ๊ฒ€์ƒ‰ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ
    ์ด๋Š” ํŠน์ • ํŒŒํ‹ฐ ๋‚ด์˜ ๋ชจ๋“  ์‚ฌ์šฉ์ž ์ ์ˆ˜๋ฅผ ์กฐํšŒํ•˜๋Š” ์ž‘์—…์—์„œ ์„ฑ๋Šฅ์ƒ ์ด์ ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
  • ์ €์žฅ ๊ณต๊ฐ„ ํšจ์œจ์„ฑ:
    ํด๋Ÿฌ์Šคํ„ฐ๋“œ ์ธ๋ฑ์Šค๋Š” ๋ฐ์ดํ„ฐ ์ž์ฒด๋ฅผ ์ธ๋ฑ์Šค ์ˆœ์„œ๋Œ€๋กœ ์ €์žฅํ•˜๋ฏ€๋กœ,
    ๋ณ„๋„์˜ ์ธ๋ฑ์Šค ๊ตฌ์กฐ๊ฐ€ ํ•„์š” ์—†์–ด ์ €์žฅ ๊ณต๊ฐ„์„ ์ ˆ์•ฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์กฐ์ธ ์„ฑ๋Šฅ:
    ํด๋Ÿฌ์Šคํ„ฐ๋“œ ์ธ๋ฑ์Šค๋Š” ์‹๋ณ„ ๊ด€๊ณ„์—์„œ ์กฐ์ธ ์„ฑ๋Šฅ์ด ์šฐ์ˆ˜ํ•ฉ๋‹ˆ๋‹ค.
  • ๋ฐ์ดํ„ฐ ๋ชจ๋ธ์˜ ๋ช…ํ™•์„ฑ:
    party_id์™€ user_id์˜ ์กฐํ•ฉ์ด ํ•ต์‹ฌ ์‹๋ณ„์ž์ž„์„ ๋ช…์‹œํ•˜๋ฉฐ
    ๋ฐ์ดํ„ฐ ๋ชจ๋ธ์„ ์ดํ•ดํ•˜๊ณ  ๊ด€๋ฆฌํ•˜๋Š” ๋ฐ์— ๋„์›€์ด ๋ฉ๋‹ˆ๋‹ค.

score ๊ด€๊ณ„

user์™€ score ๊ฐ„์˜ 1:N ๊ด€๊ณ„๋ฅผ ๋„ฃ์ง€ ์•Š์€ ์ด์œ 

  • ๋‹ค์ค‘ ๊ด€๊ณ„ ๋ฐฉ์ง€:
    user์™€ score ์‚ฌ์ด์— ์ง์ ‘์ ์ธ 1:๋‹ค ๊ด€๊ณ„๋ฅผ ํ‘œํ˜„ํ•˜๋ฉด, party์™€์˜ ๊ด€๊ณ„๊ฐ€ ๋ชจํ˜ธํ•ด์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    ํ˜„์žฌ ๊ตฌ์กฐ๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์—ฌ๋Ÿฌ ํŒŒํ‹ฐ์— ์ฐธ์—ฌํ•  ์ˆ˜ ์žˆ๊ณ , ๊ฐ ํŒŒํ‹ฐ๋งˆ๋‹ค ๋ณ„๋„์˜ ์ ์ˆ˜๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Œ์„ ๋ช…ํ™•ํžˆ ํ•ฉ๋‹ˆ๋‹ค.
  • ERD์˜ ๊ฐ„๊ฒฐ์„ฑ:
    ํ˜„์žฌ ๊ตฌ์กฐ๋Š” ํ•„์ˆ˜์ ์ธ ๊ด€๊ณ„๋งŒ์„ ํ‘œํ˜„ํ•˜์—ฌ ERD์˜ ๊ฐ€๋…์„ฑ์„ ์œ ์ง€ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
    ๋ชจ๋“  ๊ด€๊ณ„๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ํ‘œํ˜„ํ•˜๋ฉด ๋‹ค์ด์–ด๊ทธ๋žจ์ด ๋ณต์žกํ•ด์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.