diff --git a/keyword/chapter01/images/1-Wenty-Subnet-2.png b/keyword/chapter01/images/1-Wenty-Subnet-2.png new file mode 100644 index 0000000..201e138 Binary files /dev/null and b/keyword/chapter01/images/1-Wenty-Subnet-2.png differ diff --git "a/keyword/chapter01/images/2-\353\235\274\354\232\260\355\214\205-\355\205\214\354\235\264\353\270\224-\354\227\260\352\262\260.png" "b/keyword/chapter01/images/2-\353\235\274\354\232\260\355\214\205-\355\205\214\354\235\264\353\270\224-\354\227\260\352\262\260.png" new file mode 100644 index 0000000..2b00cfb Binary files /dev/null and "b/keyword/chapter01/images/2-\353\235\274\354\232\260\355\214\205-\355\205\214\354\235\264\353\270\224-\354\227\260\352\262\260.png" differ diff --git a/keyword/chapter01/images/3-Wenty-SubnetGroup.png b/keyword/chapter01/images/3-Wenty-SubnetGroup.png new file mode 100644 index 0000000..ca8d5f2 Binary files /dev/null and b/keyword/chapter01/images/3-Wenty-SubnetGroup.png differ diff --git "a/keyword/chapter01/images/4-Wenty-VPC-DNS-\355\231\234\354\204\261\355\231\224.png" "b/keyword/chapter01/images/4-Wenty-VPC-DNS-\355\231\234\354\204\261\355\231\224.png" new file mode 100644 index 0000000..64baf8e Binary files /dev/null and "b/keyword/chapter01/images/4-Wenty-VPC-DNS-\355\231\234\354\204\261\355\231\224.png" differ diff --git "a/keyword/chapter01/images/5-RDS-\354\203\235\354\204\261.png" "b/keyword/chapter01/images/5-RDS-\354\203\235\354\204\261.png" new file mode 100644 index 0000000..5f5ac43 Binary files /dev/null and "b/keyword/chapter01/images/5-RDS-\354\203\235\354\204\261.png" differ diff --git a/keyword/chapter01/images/6-Test-Connection.png b/keyword/chapter01/images/6-Test-Connection.png new file mode 100644 index 0000000..ff6892e Binary files /dev/null and b/keyword/chapter01/images/6-Test-Connection.png differ diff --git "a/keyword/chapter01/images/DB-\354\240\221\354\206\215-Test-Connection.png" "b/keyword/chapter01/images/DB-\354\240\221\354\206\215-Test-Connection.png" new file mode 100644 index 0000000..8b83d27 Binary files /dev/null and "b/keyword/chapter01/images/DB-\354\240\221\354\206\215-Test-Connection.png" differ diff --git "a/keyword/chapter01/images/\353\217\204\354\204\234-\353\214\200\354\227\254-\352\264\200\353\246\254-app-DB-\354\204\244\352\263\204-\352\263\265\353\266\200-\354\240\204.jpg" "b/keyword/chapter01/images/\353\217\204\354\204\234-\353\214\200\354\227\254-\352\264\200\353\246\254-app-DB-\354\204\244\352\263\204-\352\263\265\353\266\200-\354\240\204.jpg" new file mode 100644 index 0000000..4b1c1b7 Binary files /dev/null and "b/keyword/chapter01/images/\353\217\204\354\204\234-\353\214\200\354\227\254-\352\264\200\353\246\254-app-DB-\354\204\244\352\263\204-\352\263\265\353\266\200-\354\240\204.jpg" differ diff --git "a/keyword/chapter01/images/\353\217\204\354\204\234-\353\214\200\354\227\254-\352\264\200\353\246\254-app-DB-\354\204\244\352\263\204-\352\263\265\353\266\200-\355\233\204-\354\266\224\352\260\200\354\210\230\354\240\225.jpg" "b/keyword/chapter01/images/\353\217\204\354\204\234-\353\214\200\354\227\254-\352\264\200\353\246\254-app-DB-\354\204\244\352\263\204-\352\263\265\353\266\200-\355\233\204-\354\266\224\352\260\200\354\210\230\354\240\225.jpg" new file mode 100644 index 0000000..6d67ea0 Binary files /dev/null and "b/keyword/chapter01/images/\353\217\204\354\204\234-\353\214\200\354\227\254-\352\264\200\353\246\254-app-DB-\354\204\244\352\263\204-\352\263\265\353\266\200-\355\233\204-\354\266\224\352\260\200\354\210\230\354\240\225.jpg" differ diff --git "a/keyword/chapter01/images/\353\217\204\354\204\234-\353\214\200\354\227\254-\352\264\200\353\246\254-app-DB-\354\204\244\352\263\204-\352\263\265\353\266\200-\355\233\204.jpg" "b/keyword/chapter01/images/\353\217\204\354\204\234-\353\214\200\354\227\254-\352\264\200\353\246\254-app-DB-\354\204\244\352\263\204-\352\263\265\353\266\200-\355\233\204.jpg" new file mode 100644 index 0000000..765c462 Binary files /dev/null and "b/keyword/chapter01/images/\353\217\204\354\204\234-\353\214\200\354\227\254-\352\264\200\353\246\254-app-DB-\354\204\244\352\263\204-\352\263\265\353\266\200-\355\233\204.jpg" differ diff --git a/keyword/chapter01/keyword.md b/keyword/chapter01/keyword.md new file mode 100644 index 0000000..7531016 --- /dev/null +++ b/keyword/chapter01/keyword.md @@ -0,0 +1,242 @@ +### πŸŽ―ν•΅μ‹¬ ν‚€μ›Œλ“œ +*** +- **μ™Έλž˜ν‚€(foreign key)** + - ν•œ ν…Œμ΄λΈ”μ˜ 열이 λ‹€λ₯Έ ν…Œμ΄λΈ”μ˜ κΈ°λ³Έν‚€λ‚˜ κ³ μœ ν‚€(Unique Key)λ₯Ό μ°Έμ‘°ν•˜λŠ” 데 μ‚¬μš©λ˜λŠ” μ œμ•½ 쑰건 + - ν•œ 속성 집합을 λ¦΄λ ˆμ΄μ…˜ μŠ€ν‚€λ§ˆλ‘œλΆ€ν„° λ‹€λ₯Έ λ¦΄λ ˆμ΄μ…˜ μŠ€ν‚€λ§ˆλ₯Ό μ°Έμ‘°ν•œλ‹€. + - **foreign key constraint(μ™Έλž˜ ν‚€ μ œμ•½ 쑰건)** + - λΆ€λͺ¨ ν…Œμ΄λΈ”(μ°Έμ‘°ν•˜λŠ” ν…Œμ΄λΈ”)의 값이 μžμ‹ ν…Œμ΄λΈ”(μ°Έμ‘°λ˜λŠ” ν…Œμ΄λΈ”)μ—λ§Œ μ‘΄μž¬ν•  수 μžˆλ‹€. (두 ν…Œμ΄λΈ” κ°„μ˜ 데이터 일관성 보μž₯) + - λΆ€λͺ¨ ν…Œμ΄λΈ”μ—μ„œ μœ νš¨ν•˜μ§€ μ•Šμ€ 값을 μžμ‹ ν…Œμ΄λΈ”μ— μ‚½μž…ν•˜κ±°λ‚˜ μ°Έμ‘°ν•  수 μ—†λ‹€. +- **κΈ°λ³Έν‚€(primary key)** + - 각 ν…Œμ΄λΈ”μ˜ 행을 κ³ μœ ν•˜κ²Œ 식별할 수 λŠ” μ΄μƒμ˜ μ†μ„±λ“€μ˜ 집합 + - ν…Œμ΄λΈ”μ˜ 각 행을 ꡬ별할 수 μžˆλŠ” μœ μΌν•œ 값을 가지며 κ·Έ 값은 μ ˆλŒ€λ‘œ μ€‘λ³΅λ„κ±°λ‚˜ NULL 값을 κ°€μ§ˆ 수 μ—†λ‹€. + - κΈ°λ³Έν‚€λŠ” ν•œ 번 μ„€μ •λ˜λ©΄ 거의 λ³€κ²½λ˜μ§€ μ•ŠλŠ”λ‹€. + - λ¦΄λ ˆμ΄μ…˜ μ•ˆμ—μ„œ νŠœν”Œμ„ κ΅¬λ³„ν•˜κΈ° μœ„ν•΄ 후보 ν‚€ 쀑 ν•˜λ‚˜κ°€ κΈ°λ³Έν‚€λ‘œ μ„ νƒλœλ‹€. + - 후보킀(Candidate Key): μŠˆνΌν‚€ 쀑 λΆˆν•„μš”ν•œ 것을 μ œμ™Έν•˜μ—¬ μ΅œμ†Œλ‘œ 쀄인 ν‚€ + - μŠˆνΌν‚€(Super key): ν…Œμ΄λΈ”μ˜ 행을 κ³ μœ ν•˜κ²Œ 식별할 수 μžˆλŠ” ν•˜λ‚˜ μ΄μƒμ˜ μ†μ„±λ“€μ˜ 집합. 기본킀와 달리 좔가적인 λΆˆν•„μš”ν•œ 속성을 포함할 수 μžˆλ‹€. + - **primary key constraint(μ£Ό ν‚€ μ œμ•½ 쑰건)** + - λͺ¨λ“  속성은 NULL 값을 κ°€μ§ˆ 수 μ—†λ‹€. + - λͺ¨λ“  νŠœν”Œμ€ κ³ μœ ν•œ 값을 포함해야 ν•œλ‹€. (μ€‘λ³΅λœ 값을 가지면 μ•ˆλœλ‹€) +- **ER λ‹€μ΄μ–΄κ·Έλž¨ (Entity-Relation Diagram)** + - 개체 관계 λ‹€μ΄μ–΄κ·Έλž¨ + - λ°μ΄ν„°λ² μ΄μŠ€ μ„€κ³„μ—μ„œ μ‚¬μš©λ˜λŠ” μ€‘μš”ν•œ λ„κ΅¬λ‘œ, λ°μ΄ν„°λ² μ΄μŠ€μ— μ €μž₯될 λ°μ΄ν„°μ˜ ꡬ쑰λ₯Ό μ‹œκ°„μ μœΌλ‘œ ν‘œν˜„ν•œ 것 + - ν”„λ‘œμ νŠΈ μ‹œμž‘κ³Ό λ™μ‹œμ— μ„€κ³„ν•˜λŠ” 것이 μ’‹λ‹€. +- **볡합 ν‚€** + - 2개 μ΄μƒμ˜ 속성을 κ²°ν•©ν•˜μ—¬ ν•˜λ‚˜μ˜ κ³ μœ ν•œ μ‹λ³„μžλ‘œ μ‚¬μš©ν•˜λŠ” ν‚€ + - κΈ°λ³Έν‚€λ‘œ 섀정될 수 μžˆλ‹€. +- **연관관계** + - 2개 μ΄μƒμ˜ μ—”ν‹°ν‹° μ‚¬μ΄μ˜ 관계 μ •μ˜ + - μ—°κ΄€κ΄€κ³„μ˜ μ’…λ₯˜ + - 1:1(One-to-One): ν•œ μ—”ν‹°ν‹°κ°€ λ‹€λ₯Έ 엔티티와 μ„œλ‘œ ν•˜λ‚˜μ˜ κ³ μœ ν•œ 관계λ₯Ό λ§ΊλŠ” 경우 + - 1:N(One-to-Many): ν•œ μ—”ν‹°ν‹°κ°€ λ‹€λ₯Έ 엔티티와 μ—¬λŸ¬ 개의 관계λ₯Ό 맺을 수 μžˆλŠ” 경우 + - N:N(Many-to-Many): 두 μ—”ν‹°ν‹°κ°€ μ„œλ‘œ μ—¬λŸ¬ 개의 관계λ₯Ό 맺을 수 μžˆλŠ” 경우 + - ν‘œκΈ°λ²• + - |: 1개 / ∈: 2개 이상 (λ‹€μˆ˜) / β—‹: 0개 +- **μ •κ·œν™”** + - λ°μ΄ν„°μ˜ 쀑볡을 μ΅œμ†Œν™”ν•˜κ³  일관성을 μœ μ§€ν•˜κΈ° μœ„ν•΄ ν…Œμ΄λΈ”μ„ ꡬ쑰적으둜 λΆ„λ¦¬ν•˜κ³  각 ν…Œμ΄λΈ” κ°„μ˜ 관계λ₯Ό μ„€μ •ν•˜λŠ” κ³Όμ • + - λ°μ΄ν„°μ˜ 무결성과 일관성을 μœ μ§€ν•˜κ³  쀑볡 λ°μ΄ν„°λ‘œ μΈν•œ μ €μž₯ 곡간 낭비와 이상 ν˜„μƒμ„ λ°©μ§€ν•œλ‹€. + - 각각의 단계λ₯Ό μ •κ·œν˜•μ΄λΌκ³  ν•œλ‹€. + 1. 제 1 μ •κ·œν˜• (1NF) + - ν…Œμ΄λΈ”μ˜ λͺ¨λ“  속성이 더 이상 뢄리할 수 μ—†λŠ” μ›μžκ°’μ„ κ°€μ Έμ•Ό ν•˜λ©° ν•˜λ‚˜μ˜ μ…€μ—λŠ” ν•˜λ‚˜μ˜ κ°’λ§Œ μžˆμ–΄μ•Ό ν•œλ‹€. + - 쀑볡 데이터가 μ—†μ–΄μ•Ό ν•œλ‹€. + 2. 제 2 μ •κ·œν˜• (2NF) + - 1NFλ₯Ό λ§Œμ‘±ν•˜λ©΄μ„œ λΆ€λΆ„ ν•¨μˆ˜ 쒅속을 μ œκ±°ν•œλ‹€. 즉, κΈ°λ³Έν‚€μ˜ 일뢀가 μ•„λ‹Œ 속성은 κΈ°λ³Έν‚€ 전체에 μ’…μ†λ˜μ–΄μ•Ό ν•œλ‹€. + - κΈ°λ³Έν‚€μ˜ μΌλΆ€μ—λ§Œ μ’…μ†λœ 속성은 λ‹€λ₯Έ ν…Œμ΄λΈ”λ‘œ λΆ„λ¦¬ν•œλ‹€. + 3. 제 3 μ •κ·œν˜• (3NF) + - 제2μ •κ·œν˜•μ„ λ§Œμ‘±ν•˜λ©΄μ„œ 이행적 ν•¨μˆ˜ 쒅속(A β†’ B β†’ C)을 μ œκ±°ν•˜λŠ” 것이닀. 즉, 기본킀에 μ˜ν•΄ κ²°μ •λ˜μ§€ μ•ŠλŠ” λ‹€λ₯Έ 속성에 μ’…μ†λœ 속성이 μ—†μ–΄μ•Ό ν•œλ‹€. + 4. Boyce-Codd μ •κ·œν˜• (**BCNF)** + - 3NFλ₯Ό λ§Œμ‘±ν•˜λ©΄μ„œ λͺ¨λ“  κ²°μ •μžκ°€ 후보킀여야 ν•œλ‹€. 즉, 후보킀가 μ•„λ‹Œ 속성이 κ²°μ •μžκ°€ λ˜μ–΄μ„  μ•ˆ λ©λ‹ˆλ‹€. +- **반 μ •κ·œν™”** + - λ°μ΄ν„°μ˜ 쑰회 μ„±λŠ₯을 ν–₯μƒμ‹œν‚€κΈ° μœ„ν•΄ λ°μ΄ν„°μ˜ 쀑볡을 ν—ˆμš©ν•˜κ±°λ‚˜ 데이터λ₯Ό κ·Έλ£Ήν•‘ν•˜λŠ” κ³Όμ • + - μ •κ·œν™”λŠ” μ§€λ‚˜μΉ˜κ²Œ λΆ„λ¦¬λœ ν…Œμ΄λΈ” κ°„μ˜ 쑰인(Join)이 λ§Žμ•„μ§ˆ 경우 쿼리 μ„±λŠ₯이 μ €ν•˜λ  수 μžˆλ‹€. β†’ μ΄λŸ¬ν•œ μ„±λŠ₯ 문제λ₯Ό ν•΄κ²°ν•˜κΈ° μœ„ν•΄ μ •κ·œν™”λœ ꡬ쑰λ₯Ό μ™„ν™”ν•˜λŠ” μ „λž΅μ΄λ‹€. + - μ •κ·œν™”λ₯Ό μ‹œλ„ν•œ 후에 μ„±λŠ₯ μƒμ˜ μ΄μŠˆκ°€ λ°œμƒν•  λ•Œ λ°μ΄ν„°λ² μ΄μŠ€μ˜ μ„±λŠ₯을 ν–₯μƒμ‹œν‚€κΈ° μœ„ν•΄ μ‚¬μš©λœλ‹€. + - λ°˜μ •κ·œν™” λ°©λ²•μ—λŠ” ν…Œμ΄λΈ” 병합/μΆ”κ°€/뢄할이 μžˆλ‹€. + +### πŸ“¦Β μ‹€μŠ΅ +--- +#### λ„μ„œ λŒ€μ—¬ 관리 app λ°μ΄ν„°λ² μ΄μŠ€ 섀계 + +**μ›Œν¬λΆ κ³΅λΆ€ν•˜κΈ° μ „μ˜ DB 섀계** (*~~엉망이닀~~*) +![images/λ„μ„œ-λŒ€μ—¬-관리-app-DB-섀계-곡뢀-μ „.jpg](images/λ„μ„œ-λŒ€μ—¬-관리-app-DB-섀계-곡뢀-μ „.jpg) +- λ†“μΉœ 점 + - N:M(λ‹€λŒ€λ‹€) 관계λ₯Ό 섀계할 λ•ŒλŠ” μ§μ ‘μ μœΌλ‘œ 두 ν…Œμ΄λΈ”μ„ μ—°κ²°ν•˜μ§€ μ•Šκ³ , 쀑간 ν…Œμ΄λΈ”(맀핑 ν…Œμ΄λΈ”)을 μ‚¬μš©ν•˜μ—¬ 1:N κ΄€κ³„λ‘œ 뢄리해야 ν•œλ‹€. + - μ‚¬μš©μžμ™€ 책은 N:M 관계이닀. + - λ‚˜λŠ” 이λ₯Ό μ‹œκ°„ κ°œλ…μ€ λ¬΄μ‹œν•˜κ³  ν•œ ꢌ의 책을 μ—¬λŸ¬ μ‚¬μš©μžκ°€ λŒ€μ—¬ν•œ κ²ƒμœΌλ‘œ μ΄ν•΄ν–ˆλ‹€. ν•œ ꢌ의 책에 λŒ€ν•œ λŒ€μ—¬ 내역을 κΈ°λ‘ν•˜λ“―μ΄ 말이닀. + - μ‚¬μš©μžμ™€ 책은 likes λΌλŠ” 관계(μ‚¬μš©μžκ°€ 책에 μ’‹μ•„μš”λ₯Ό λˆ„λ₯Ό μˆ˜λ„ μžˆλŠ” 관계)κ°€ μ‘΄μž¬ν•œλ‹€. + - 곡지사항에 λŒ€ν•œ μ•Œλ¦Ό μ²˜λ¦¬μ™€ λ§ˆμΌ€νŒ…μ— λŒ€ν•œ μ•Œλ¦Ό μ²˜λ¦¬κ°€ 각각 λ‹€λ₯Ό 수 μžˆλ‹€. + - μ•Œλ¦Όμ— λŒ€ν•œ μ„±μ§ˆμ€ λ™μΌν•˜λ‹ˆ μŠˆνΌνƒ€μž…-μ„œλΈŒνƒ€μž…μ„ μ΄μš©ν•˜μ—¬ κ³΅ν†΅λœ 속성을 상속 λ°›λŠ”λ‹€. + - μΆ”κ°€μ μœΌλ‘œ, "μ‚¬μš©μž κ°„ 차단 κΈ°λŠ₯이 μƒκΈ°κ²Œ λ˜μ–΄ 차단 ν•œ μ‚¬μš©μžκ°€ λˆ„λ₯Έ μ’‹μ•„μš”λŠ” 집계λ₯Ό ν•˜μ§€ μ•ŠλŠ”λ‹€."λΌλŠ” μš”κ΅¬μ‚¬ν•­μ„ λ°˜μ˜ν•΄ block ν…Œμ΄λΈ”μ„ μƒμ„±ν•˜κ³  member ν…Œμ΄λΈ”κ³Ό 1:N κ΄€κ³„λ‘œ μ—°κ²°ν•΄μ£Όμ—ˆλ‹€. + - μ„œλΈŒνƒ€μž…μ€ ν•˜λ‚˜μ˜ μŠˆνΌνƒ€μž…λ§Œμ„ 상속받을 수 있고 μŠˆνΌνƒ€μž…:μ„œλΈŒνƒ€μž…μ€ 1:N 관계가 κ°€λŠ₯ν•˜λ‹€. + - μΆ”ν›„ 데이터 관리 및 μœ μ§€λ³΄μˆ˜λ₯Ό μœ„ν•΄ ν…Œμ΄λΈ”λ§ˆλ‹€ created_at, updated_at을 μΆ”κ°€ν•˜λŠ” 게 μ’‹λ‹€. + +**μ›Œν¬λΆ κ³΅λΆ€ν•œ ν›„μ˜ μ΅œμ’… DB 섀계** +![images/λ„μ„œ-λŒ€μ—¬-관리-app-DB-섀계-곡뢀-ν›„-μΆ”κ°€μˆ˜μ •.jpg](images/λ„μ„œ-λŒ€μ—¬-관리-app-DB-섀계-곡뢀-ν›„-μΆ”κ°€μˆ˜μ •.jpg) + +**MySQL ν…Œμ΄λΈ” 생성** +``` +CREATE TABLE member ( + id BIGINT NOT NULL AUTO_INCREMENT, + member_name VARCHAR(20) NOT NULL, + nickname VARCHAR(20) NOT NULL, + phone_number varchar(13) NOT NULL, + gender int NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + active int NOT NULL, + inactive_date datetime(6) NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE category ( + id BIGINT NOT NULL AUTO_INCREMENT, + title varchar(20) NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE book ( + id BIGINT NOT NULL AUTO_INCREMENT, + category_id BIGINT NOT NULL, + title varchar(30) NOT NULL, + introduction text NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (category_id) REFERENCES member(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE likes ( + id BIGINT NOT NULL AUTO_INCREMENT, + member_id BIGINT NOT NULL, + book_id BIGINT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (member_id) REFERENCES member(id) ON DELETE CASCADE, + FOREIGN KEY (book_id) REFERENCES book(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE member_book ( + id BIGINT NOT NULL AUTO_INCREMENT, + member_id BIGINT NOT NULL, + book_id BIGINT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (member_id) REFERENCES member(id) ON DELETE CASCADE, + FOREIGN KEY (book_id) REFERENCES book(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE alarm ( + id BIGINT NOT NULL AUTO_INCREMENT, + member_id BIGINT NOT NULL, + is_conformed int NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (member_id) REFERENCES member(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE alarm_notice ( + id BIGINT NOT NULL AUTO_INCREMENT, + alarm_id BIGINT NOT NULL, + title varchar(20) NOT NULL, + body TEXT NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (alarm_id) REFERENCES alarm(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE alarm_book_return_time ( + id BIGINT NOT NULL AUTO_INCREMENT, + alarm_id BIGINT NOT NULL, + title varchar(20) NOT NULL, + body TEXT NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (alarm_id) REFERENCES alarm(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE alarm_marketing ( + id BIGINT NOT NULL AUTO_INCREMENT, + alarm_id BIGINT NOT NULL, + title varchar(20) NOT NULL, + body TEXT NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (alarm_id) REFERENCES alarm(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE hash_tag ( + id BIGINT NOT NULL AUTO_INCREMENT, + title varchar(20) NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE book_hash_tag ( + id BIGINT NOT NULL AUTO_INCREMENT, + book_id BIGINT NOT NULL, + hash_tag_id BIGINT NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (book_id) REFERENCES book(id) ON DELETE CASCADE, + FOREIGN KEY (hash_tag_id) REFERENCES hash_tag(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE block ( + id BIGINT NOT NULL AUTO_INCREMENT, + blocker_id BIGINT NOT NULL, + blocked_id BIGINT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (blocker_id) REFERENCES member(id) ON DELETE CASCADE, + FOREIGN KEY (blocked_id) REFERENCES member(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +``` +- ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 + - MySQLμ—μ„œ ν…Œμ΄λΈ”μ„ 생성할 λ•Œ μ‚¬μš©ν•˜λŠ” μ˜΅μ…˜μœΌλ‘œ, μŠ€ν† λ¦¬μ§€ 엔진과 문자 인코딩 방식을 μ •μ˜ν•œλ‹€. + - ENGINE=InnoDB: MySQLμ—μ„œ κ°€μž₯ 많이 μ‚¬μš©λ˜λŠ” μŠ€ν† λ¦¬μ§€ 엔진 + - DEFAULT CHARSET: ν…Œμ΄λΈ”μ—μ„œ μ‚¬μš©ν•  문자 인코딩 방식 + +#### 둜컬 DB μ„ΈνŒ… 및 접속 + +![images/DB-접속-Test=Connection](images/DB-접속-Test-Connection.png) +둜컬 DB 접속 +- (μ‚¬μš©μž μ„€μ •ν•˜μ§€ μ•Šμ•˜μœΌλ©΄ root) +- Test Connection 성곡! πŸ˜€ + +#### ν΄λΌμš°λ“œ ν™˜κ²½(AWS)μ—μ„œμ˜ DB 접속 + +![images/1-Wenty-Subnet-2.png](images/1-Wenty-Subnet-2.png) +μ„œλΈŒλ„· μΆ”κ°€ 생성 +- Wenty-VPC의 퍼블릭 μ„œλΈŒλ„·μ— RDSλ₯Ό λ°°μΉ˜ν•œλ‹€. +- β€œWenty-Subnet-2” μ„œλΈŒλ„·μ„ μΆ”κ°€ μƒμ„±ν•œλ‹€. + - IP λŒ€μ—­: 10.0.3.0/24 + - RDSλŠ” λ§Œμ•½μ„ λŒ€λΉ„ν•΄ μ„œλΈŒλ„· 2개λ₯Ό μš”κ΅¬ν•˜κΈ° λ•Œλ¬Έμ— 2개의 μ„œλΈŒλ„·μ„ 지정해주어야 ν•œλ‹€. + +![images/2-λΌμš°νŒ…-ν…Œμ΄λΈ”-μ—°κ²°.png](images/2-λΌμš°νŒ…-ν…Œμ΄λΈ”-μ—°κ²°.png) +λΌμš°νŒ… ν…Œμ΄λΈ”μ— μ—°κ²° +- Wenty-Subnet-2 μ„œλΈŒλ„·μ„ 퍼블릭 μ„œλΈŒλ„·μœΌλ‘œ λ§Œλ“€κΈ° μœ„ν•΄ 외뢀와 μ—°κ²°λœ λΌμš°νŒ… ν…Œμ΄λΈ”μ— μ—°κ²°ν•΄μ€€λ‹€. + +![images/3-Wenty-SubnetGroup](images/3-Wenty-SubnetGroup.png) +DB μ„œλΈŒλ„· κ·Έλ£Ή 생성 +- β€œWenty-SubnetGroup” μ„œλΈŒλ„· κ·Έλ£Ή 생성 + - VPC - Wenty-VPC μ„€μ • + - 퍼블릭 μ„œλΈŒλ„· - 2개의 퍼블릭 μ„œλΈŒλ„· Wenty-Subnet, Wenty-Subnet-2 μ„€μ • + +![images/4-Wenty-VPC-DNS-ν™œμ„±ν™”](images/4-Wenty-VPC-DNS-ν™œμ„±ν™”.png) +DNS 호슀트 이름 ν™œμ„±ν™” +- Wenty-VPC의 DNS 호슀트 이름을 ν™œμ„±ν™”ν•΄μ€€λ‹€. + +![images/5-RDS-생성](images/5-RDS-생성.png) +RDS 생성 +- β€œWenth-DB” λ°μ΄ν„°λ² μ΄μŠ€ 생성 + - λ§ˆμŠ€ν„° μ‚¬μš©μž 이름 β€œWenty” μ„€μ • + - VPC - Wenty-VPC μ„€μ • + - μ„œλΈŒλ„· κ·Έλ£Ή - Wenty-SubnetGroup μ„€μ • + +![images/6-Test-Connection](images/6-Test-Connection.png) +RDS 원격 접속 +- 호슀트 - Wenty-DB의 μ•€λ“œν¬μΈνŠΈ +- μ‚¬μš©μž - Wenty +- Test Connection 성곡! πŸ˜€ \ No newline at end of file diff --git "a/mission/chapter01/images/\352\260\200\352\262\214-\353\260\251\353\254\270-\353\257\270\354\205\230-\355\217\254\354\235\270\355\212\270-\354\204\234\353\271\204\354\212\244-\354\212\244\355\204\260\353\224\224-\355\233\204-\354\266\224\352\260\200\354\210\230\354\240\225.jpg" "b/mission/chapter01/images/\352\260\200\352\262\214-\353\260\251\353\254\270-\353\257\270\354\205\230-\355\217\254\354\235\270\355\212\270-\354\204\234\353\271\204\354\212\244-\354\212\244\355\204\260\353\224\224-\355\233\204-\354\266\224\352\260\200\354\210\230\354\240\225.jpg" new file mode 100644 index 0000000..b1fb304 Binary files /dev/null and "b/mission/chapter01/images/\352\260\200\352\262\214-\353\260\251\353\254\270-\353\257\270\354\205\230-\355\217\254\354\235\270\355\212\270-\354\204\234\353\271\204\354\212\244-\354\212\244\355\204\260\353\224\224-\355\233\204-\354\266\224\352\260\200\354\210\230\354\240\225.jpg" differ diff --git "a/mission/chapter01/images/\352\260\200\352\262\214-\353\260\251\353\254\270-\353\257\270\354\205\230-\355\217\254\354\235\270\355\212\270-\354\204\234\353\271\204\354\212\244-\354\212\244\355\204\260\353\224\224-\355\233\204.jpg" "b/mission/chapter01/images/\352\260\200\352\262\214-\353\260\251\353\254\270-\353\257\270\354\205\230-\355\217\254\354\235\270\355\212\270-\354\204\234\353\271\204\354\212\244-\354\212\244\355\204\260\353\224\224-\355\233\204.jpg" new file mode 100644 index 0000000..3918221 Binary files /dev/null and "b/mission/chapter01/images/\352\260\200\352\262\214-\353\260\251\353\254\270-\353\257\270\354\205\230-\355\217\254\354\235\270\355\212\270-\354\204\234\353\271\204\354\212\244-\354\212\244\355\204\260\353\224\224-\355\233\204.jpg" differ diff --git "a/mission/chapter01/images/\352\260\200\352\262\214-\353\260\251\353\254\270-\353\257\270\354\205\230-\355\217\254\354\235\270\355\212\270-\354\204\234\353\271\204\354\212\244.jpg" "b/mission/chapter01/images/\352\260\200\352\262\214-\353\260\251\353\254\270-\353\257\270\354\205\230-\355\217\254\354\235\270\355\212\270-\354\204\234\353\271\204\354\212\244.jpg" new file mode 100644 index 0000000..d5c5fa2 Binary files /dev/null and "b/mission/chapter01/images/\352\260\200\352\262\214-\353\260\251\353\254\270-\353\257\270\354\205\230-\355\217\254\354\235\270\355\212\270-\354\204\234\353\271\204\354\212\244.jpg" differ diff --git a/mission/chapter01/mission.md b/mission/chapter01/mission.md new file mode 100644 index 0000000..adfa051 --- /dev/null +++ b/mission/chapter01/mission.md @@ -0,0 +1,381 @@ +### πŸ”₯ λ―Έμ…˜ +*** +#### μŠ€ν„°λ”” μ „μ˜ DB 섀계 + +**ERD 섀계** +![images/κ°€κ²Œ-λ°©λ¬Έ-λ―Έμ…˜-포인트-μ„œλΉ„μŠ€](images/κ°€κ²Œ-λ°©λ¬Έ-λ―Έμ…˜-포인트-μ„œλΉ„μŠ€.jpg) + +**MySQL ν…Œμ΄λΈ” 생성** +``` +CREATE TABLE member ( + id INT NOT NULL AUTO_INCREMENT, + email VARCHAR(50) NOT NULL, + member_name VARCHAR(30) NOT NULL, + nickname VARCHAR(30) NOT NULL, + gender INT NOT NULL, + birth varchar(10) NOT NULL, + residence varchar(50) NOT NULL, + points INT DEFAULT 0 NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + active INT NOT NULL, + inactive_at datetime(6) NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE food_kind ( + id INT NOT NULL AUTO_INCREMENT, + kind VARCHAR(10) NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE member_food_kind ( + id INT NOT NULL AUTO_INCREMENT, + member_id INT NOT NULL, + food_kind_id INT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (member_id) REFERENCES member(id) ON DELETE CASCADE, + FOREIGN KEY (food_kind_id) REFERENCES food_kind(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE restaurant ( + id INT NOT NULL AUTO_INCREMENT, + restaurant_name VARCHAR(30) NOT NULL, + introduction TEXT NOT NULL, + restaurant_location TEXT NOT NULL, + start_time TIMESTAMP NOT NULL, + end_time TIMESTAMP NOT NULL, + total_rating decimal(2, 1) DEFAULT 0 NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE mission ( + id INT NOT NULL AUTO_INCREMENT, + restaurant_id INT NOT NULL, + mission_name VARCHAR(30) NOT NULL, + introduction TEXT NOT NULL, + ongoing int NOT NULL, + is_completed int NOT NULL, + dday int NOT NULL, + points int NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (restaurant_id) REFERENCES restaurant(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE member_mission ( + id INT NOT NULL AUTO_INCREMENT, + member_id INT NOT NULL, + mission_id INT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (member_id) REFERENCES member(id) ON DELETE CASCADE, + FOREIGN KEY (mission_id) REFERENCES mission(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE review ( + id INT NOT NULL AUTO_INCREMENT, + member_id INT NOT NULL, + restaurant_id INT NOT NULL, + rating decimal(2, 1) NOT NULL, + content TEXT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (member_id) REFERENCES member(id) ON DELETE CASCADE, + FOREIGN KEY (restaurant_id) REFERENCES restaurant(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE reply ( + id INT NOT NULL AUTO_INCREMENT, + member_id INT NOT NULL, + review_id INT NOT NULL, + writer varchar(30) NOT NULL, + content TEXT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (member_id) REFERENCES member(id) ON DELETE CASCADE, + FOREIGN KEY (review_id) REFERENCES review(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE review_image ( + id INT NOT NULL AUTO_INCREMENT, + review_id INT NOT NULL, + image_url TEXT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (review_id) REFERENCES review(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE inquiry ( + id INT NOT NULL AUTO_INCREMENT, + member_id INT NOT NULL, + title VARCHAR(30) NOT NULL, + content TEXT NOT NULL, + is_conformed INT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (member_id) REFERENCES member(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE inquiry_image ( + id INT NOT NULL AUTO_INCREMENT, + inquiry_id INT NOT NULL, + image_url TEXT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (inquiry_id) REFERENCES inquiry(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE food_kind_restaurant ( + id INT NOT NULL AUTO_INCREMENT, + food_kind_id INT NOT NULL, + restaurant_id INT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (food_kind_id) REFERENCES food_kind(id) ON DELETE CASCADE, + FOREIGN KEY (restaurant_id) REFERENCES restaurant(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE restaurant_image ( + id INT NOT NULL AUTO_INCREMENT, + restaurant_id INT NOT NULL, + image_url TEXT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (restaurant_id) REFERENCES restaurant(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE alarm ( + id INT NOT NULL AUTO_INCREMENT, + member_id INT NOT NULL, + is_conformed INT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (member_id) REFERENCES member(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE new_mission ( + id INT NOT NULL AUTO_INCREMENT, + alarm_id INT NOT NULL, + title VARCHAR(30) NOT NULL, + body TEXT NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (alarm_id) REFERENCES alarm(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE review_request ( + id INT NOT NULL AUTO_INCREMENT, + alarm_id INT NOT NULL, + title VARCHAR(30) NOT NULL, + body TEXT NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (alarm_id) REFERENCES alarm(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +``` +#### μŠ€ν„°λ”” ν›„μ˜ DB 섀계 + +**ERD 섀계** +![images/κ°€κ²Œ-λ°©λ¬Έ-λ―Έμ…˜-포인트-μ„œλΉ„μŠ€-μŠ€ν„°λ””-ν›„-μΆ”κ°€μˆ˜μ •](images/κ°€κ²Œ-λ°©λ¬Έ-λ―Έμ…˜-포인트-μ„œλΉ„μŠ€-μŠ€ν„°λ””-ν›„-μΆ”κ°€μˆ˜μ •.jpg) +**MySQL ν…Œμ΄λΈ” 생성** +``` +CREATE TABLE map ( + id BIGINT NOT NULL AUTO_INCREMENT, + x BIGINT NOT NULL, + y BIGINT NOT NULL, + map_location TEXT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE member ( + id BIGINT NOT NULL AUTO_INCREMENT, + residence_id BIGINT NOT NULL, + email VARCHAR(50) NOT NULL, + phone_number varchar(15) NULL, + member_name VARCHAR(30) NOT NULL, + nickname VARCHAR(30) NOT NULL, + gender INT NOT NULL, + birth varchar(10) NOT NULL, + points BIGINT DEFAULT 0 NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + active INT NOT NULL, + inactive_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (residence_id) REFERENCES map(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE food_kind ( + id BIGINT NOT NULL AUTO_INCREMENT, + kind VARCHAR(10) NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE member_food_kind ( + id BIGINT NOT NULL AUTO_INCREMENT, + member_id BIGINT NOT NULL, + food_kind_id BIGINT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (member_id) REFERENCES member(id) ON DELETE CASCADE, + FOREIGN KEY (food_kind_id) REFERENCES food_kind(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE restaurant ( + id BIGINT NOT NULL AUTO_INCREMENT, + location_id BIGINT NOT NULL, + restaurant_name VARCHAR(30) NOT NULL, + introduction TEXT NOT NULL, + start_time TIMESTAMP NOT NULL, + end_time TIMESTAMP NOT NULL, + total_rating decimal(2, 1) DEFAULT 0 NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (location_id) REFERENCES map(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE mission ( + id BIGINT NOT NULL AUTO_INCREMENT, + restaurant_id BIGINT NOT NULL, + mission_name VARCHAR(30) NOT NULL, + introduction TEXT NOT NULL, + ongoing INT NOT NULL, + is_completed INT NOT NULL, + dday INT NULL, + points BIGINT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (restaurant_id) REFERENCES restaurant(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE member_mission ( + id BIGINT NOT NULL AUTO_INCREMENT, + member_id BIGINT NOT NULL, + mission_id BIGINT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (member_id) REFERENCES member(id) ON DELETE CASCADE, + FOREIGN KEY (mission_id) REFERENCES mission(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE review ( + id BIGINT NOT NULL AUTO_INCREMENT, + member_id BIGINT NOT NULL, + restaurant_id BIGINT NOT NULL, + rating decimal(2, 1) NOT NULL, + content TEXT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (member_id) REFERENCES member(id) ON DELETE CASCADE, + FOREIGN KEY (restaurant_id) REFERENCES restaurant(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE reply ( + id BIGINT NOT NULL AUTO_INCREMENT, + member_id BIGINT NOT NULL, + review_id BIGINT NOT NULL, + writer varchar(30) NOT NULL, + content TEXT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (member_id) REFERENCES member(id) ON DELETE CASCADE, + FOREIGN KEY (review_id) REFERENCES review(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE inquiry ( + id BIGINT NOT NULL AUTO_INCREMENT, + member_id BIGINT NOT NULL, + title VARCHAR(30) NOT NULL, + content TEXT NOT NULL, + is_conformed INT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (member_id) REFERENCES member(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE food_kind_restaurant ( + id BIGINT NOT NULL AUTO_INCREMENT, + food_kind_id BIGINT NOT NULL, + restaurant_id BIGINT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (food_kind_id) REFERENCES food_kind(id) ON DELETE CASCADE, + FOREIGN KEY (restaurant_id) REFERENCES restaurant(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE image ( + id BIGINT NOT NULL AUTO_INCREMENT, + restaurant_id BIGINT NOT NULL, + inquiry_id BIGINT NOT NULL, + review_id BIGINT NOT NULL, + image_url TEXT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (restaurant_id) REFERENCES restaurant(id) ON DELETE CASCADE, + FOREIGN KEY (inquiry_id) REFERENCES inquiry(id) ON DELETE CASCADE, + FOREIGN KEY (review_id) REFERENCES review(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE alarm ( + id BIGINT NOT NULL AUTO_INCREMENT, + member_id BIGINT NOT NULL, + is_conformed INT NOT NULL, + created_at datetime(6) NOT NULL, + updated_at datetime(6) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (member_id) REFERENCES member(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE alarm_new_mission ( + id BIGINT NOT NULL AUTO_INCREMENT, + alarm_id BIGINT NOT NULL, + title VARCHAR(30) NOT NULL, + body TEXT NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (alarm_id) REFERENCES alarm(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE alarm_review_request ( + id BIGINT NOT NULL AUTO_INCREMENT, + alarm_id BIGINT NOT NULL, + title VARCHAR(30) NOT NULL, + body TEXT NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (alarm_id) REFERENCES alarm(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; +``` +- 무슨 μ΄μœ μ—μ„ μ§€ λͺ¨λ₯΄κ² μ§€λ§Œ ER-λ‹€μ΄μ–΄κ·Έλž¨μ—μ„œ 1:N 관계일 κ²½μš°μ—” N에 ν•΄λ‹Ήν•˜λŠ” ν…Œμ΄λΈ”μ— μ™Έλž˜ν‚€λ₯Ό ν¬ν•¨μ‹œν‚€λŠ” κ²ƒμœΌλ‘œ κ°„μ£Όν•˜κ³  ν…Œμ΄λΈ”μ—” λ”°λ‘œ ν‘œμ‹œν•˜μ§€ μ•ŠλŠ”(?) κ²ƒμœΌλ‘œ μ°©κ°ν•˜κ³  μžˆμ—ˆλ‹€. +- ν•œ μŒμ‹μ μ— μ—¬λŸ¬ 개의 λ―Έμ…˜μ΄ μ£Όμ–΄μ§ˆ μˆ˜λ„ μžˆλ‹€. 즉, μŒμ‹μ :λ―Έμ…˜ = 1:N + - ex. OO 쀑ꡭ집 -> 10000원 μ΄μƒμ˜ 식사λ₯Ό ν•˜μ„Έμš”!, 짜μž₯면을 10λΆ„ μ•ˆμ— λ“œμ„Έμš”! λ“± +- new_mission, review_request ν…Œμ΄λΈ”μ€ ν…Œμ΄λΈ” μ΄λ¦„λ§Œ 보면 alarm ν…Œμ΄λΈ”κ³Ό 관계가 μžˆλŠ”μ§€ μ•ŒκΈ° μ–΄λ ΅λ‹€. alarm_new_mission, alarm_review_requeat와 같이 alarmκ³Ό 관계가 μžˆλŠ” ν…Œμ΄λΈ”μž„μ„ μ•Œ 수 μžˆλ„λ‘ ν‘œκΈ°ν•˜μ˜€λ‹€. +- 리뷰, λ¬Έμ˜ν•˜κΈ°, μŒμ‹μ  μ†Œκ°œλž€ λ“±μ—μ„œ μ—¬λŸ¬ 개의 사진을 첨뢀할 수 μžˆμ–΄ review_image, restaurant_image, inquiry_image ν…Œμ΄λΈ”μ„ 생성해 review, restaurant, inquiry ν…Œμ΄λΈ”λ“€μ„ 각각 μ°Έμ‘°ν•˜λ„λ‘ ν•˜μ˜€λ‹€. κ·ΈλŸ¬λ‚˜ ν•˜λ‚˜μ˜ image ν…Œμ΄λΈ”μ„ λ§Œλ“€μ–΄ μ†μ„±μœΌλ‘œ 각각의 사진듀을 μ €μž₯ν•  수 μžˆλ„λ‘ μ„€κ³„ν•˜λŠ” 방법도 μžˆλ‹€κ³  ν•΄μ„œ λ°˜μ˜ν•΄λ³΄μ•˜λ‹€. +- μ§€λ„μ—μ„œ x μ’Œν‘œ, y μ’Œν‘œλ₯Ό μ •ν•΄ 각 μœ„μΉ˜λ₯Ό μ§€μ •ν•œ map ν…Œμ΄λΈ”μ„ μΆ”κ°€ν•΄ μ‚¬μš©μž(member)의 거주지와 μŒμ‹μ (restaurant)의 μœ„μΉ˜κ°€ μ°Έμ‘°ν•˜λ„λ‘ ν•˜μ˜€λ‹€. \ No newline at end of file