-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다 👍
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'); |
There was a problem hiding this comment.
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() 이런 함수가 있었네요
VALUES (last_insert_id(), 'NULL', 'WEEKDAYS', '24시간', '24시간'), | ||
(last_insert_id(), 'NULL', 'WEEKEND', '24시간', '24시간'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
R
NULL 값이 문자열로 들어가 있습니당
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앗 그렇네요 감사합니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다! 👍
명세 관련한 부분도 일부 수정된 것 같은데 다음부터는 PR이름이나 내용에 관련 설명이 추가되면 좋을 것 같아요
리뷰 확인 부탁드립니다!
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', '휴점', '휴점'); |
There was a problem hiding this comment.
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문 두개만으로 모든 데이터를 삽입할 수 있어 보입니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coop_shop
과 coop_opens
로 insert문을 묶고, coop_opens
가 참조하는 외래키는 last_insert_id()
, last_insert_id() + 1
, last_insert_id() + 2
... 와 같이 묶을 수 있다는 말 맞을까요?
There was a problem hiding this comment.
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'),
🔥 연관 이슈
🚀 작업 내용
coopshop
에 기존 데이터가 없는 로컬에서도 동작하도록 flyway 쿼리를 수정하였습니다.coopshop
정보를 추가하면서 로컬과의auto_increment
시작 id
가 차이가 나 발생하는 오류를 수정하였습니다.💬 리뷰 중점사항