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

fix : coopshop 기존 데이터가 없는 로컬에서도 동작하도록 flyway 쿼리 수정 #957

Merged
merged 5 commits into from
Oct 11, 2024

Conversation

Choon0414
Copy link
Contributor

🔥 연관 이슈

  • close #이슈번호

🚀 작업 내용

  1. coopshop에 기존 데이터가 없는 로컬에서도 동작하도록 flyway 쿼리를 수정하였습니다.
    • 초기에 직접 DB에 coopshop 정보를 추가하면서 로컬과의 auto_increment 시작 id가 차이가 나 발생하는 오류를 수정하였습니다.

💬 리뷰 중점사항

@Choon0414 Choon0414 added 버그 정상적으로 동작하지 않는 문제상황입니다. Team Campus 캠퍼스 팀에서 작업할 이슈입니다 labels Oct 9, 2024
@Choon0414 Choon0414 self-assigned this Oct 9, 2024
Copy link

github-actions bot commented Oct 9, 2024

Unit Test Results

319 tests   318 ✔️  1m 11s ⏱️
  36 suites      1 💤
  36 files        0

Results for commit 2c8d4d3.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@kih1015 kih1015 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다 👍

Comment on lines 14 to 18
INSERT INTO `coop_shop` (`name`, `phone`, `location`, `remarks`, `semester_id`)
VALUES ('대즐', '041-560-1779', '복지관 1층', '배달 서비스, 공·일요일 미운영', 1);
INSERT INTO coop_opens (`coop_shop_id`, `type`, `day_of_week`, `open_time`, `close_time`)
VALUES (last_insert_id(), NULL, 'WEEKDAYS', '08:30', '21:00'),
(last_insert_id(), NULL, 'SATURDAY', '11:00', '18:00');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A

참조 id를 알 수 없는 경우 어떻게 넣어줄 수 있나 고민했었는데
last_insert_id() 이런 함수가 있었네요

Comment on lines 53 to 54
VALUES (last_insert_id(), 'NULL', 'WEEKDAYS', '24시간', '24시간'),
(last_insert_id(), 'NULL', 'WEEKEND', '24시간', '24시간');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

R

NULL 값이 문자열로 들어가 있습니당

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 그렇네요 감사합니다

Copy link
Collaborator

@songsunkook songsunkook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다! 👍
명세 관련한 부분도 일부 수정된 것 같은데 다음부터는 PR이름이나 내용에 관련 설명이 추가되면 좋을 것 같아요
리뷰 확인 부탁드립니다!

Comment on lines 20 to 24
INSERT INTO `coop_shop` (`name`, `phone`, `location`, `remarks`, `semester_id`)
VALUES ('서점', '041-560-1756', '복지관 1층', '점심시간 12:00 - 13:00', 1);
INSERT INTO coop_opens (`coop_shop_id`, `type`, `day_of_week`, `open_time`, `close_time`)
VALUES (last_insert_id(), NULL, 'WEEKDAYS', '09:00', '18:00'),
(last_insert_id(), NULL, 'WEEKEND', '휴점', '휴점');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C

insert 구문이 전부 동일한 형태에 value만 다른 것 같은데, 기존처럼 단일 insert문으로 묶어버리는 건 어떻게 생각하시나요??
LAST_INSERT_ID()의 정확한 반환값은 마지막 INSERT 구문의 최초 삽입 id 으로 알고 있습니다.
단일 데이터 삽입 시 마지막으로 삽입된 데이터 id를 반환하지만 단일 INSERT문으로 다중 데이터 삽입 시 삽입된 데이터 중 첫 id값을 반환합니다. 이 특성을 활용하면 기존과 같이 insert문 두개만으로 모든 데이터를 삽입할 수 있어 보입니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coop_shopcoop_opens로 insert문을 묶고, coop_opens가 참조하는 외래키는 last_insert_id(), last_insert_id() + 1, last_insert_id() + 2 ... 와 같이 묶을 수 있다는 말 맞을까요?

Copy link
Collaborator

@songsunkook songsunkook Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용자 정의 변수를 사용하는 방향을 생각했습니다.

예시

SET @FIRST_ID = LAST_INSERT_ID();

INSERT INTO coop_opens (`coop_shop_id`, `type`, `day_of_week`, `open_time`, `close_time`)
    VALUES
    (@FIRST_ID, '점심', 'WEEKDAYS', '11:40', '13:30'),
    (@FIRST_ID, '점심', 'WEEKEND', '미운영', '미운영'),
    (@FIRST_ID + 1, 'NULL', 'WEEKDAYS', '08:30', '21:00'),
    (@FIRST_ID + 1, 'NULL', 'SATURDAY', '11:00', '18:00'),

참고자료

@Choon0414 Choon0414 merged commit 6442cd9 into develop Oct 11, 2024
3 checks passed
@Choon0414 Choon0414 deleted the fix/alter-coopshop-flyway branch October 11, 2024 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Campus 캠퍼스 팀에서 작업할 이슈입니다 버그 정상적으로 동작하지 않는 문제상황입니다.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants