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] 타임라인 존재 시에도 경기 삭제 가능 #289

Open
Zena0128 opened this issue Oct 21, 2024 · 4 comments · May be fixed by #293
Open

[FIX] 타임라인 존재 시에도 경기 삭제 가능 #289

Zena0128 opened this issue Oct 21, 2024 · 4 comments · May be fixed by #293
Assignees

Comments

@Zena0128
Copy link
Contributor

No description provided.

@Zena0128
Copy link
Contributor Author

Zena0128 commented Nov 6, 2024

  • @OnDelete는 부모를 먼저 삭제한 후, 해당 부모를 참조하는 자식들 삭제 ⇒ 직접 데이터베이스에 on delete cascade를 걸어주지 않으면 참조 무결성 제약을 위반해 오류 발생!
    • 이 친구는 DDL에서만 먹히는 친구라, 우리 서비스의 경우 ddl-auto = update로 되어 있어 중간에 해당 어노테이션을 붙이면 적용이 안 됨. 효과가 없음
    • 따라서 직접 MySQL워크벤치에서 cascade 제약조건을 걸어주어 해결
ALTER TABLE timelines
ADD CONSTRAINT FK_TIMELINES_ON_GAME FOREIGN KEY (game_id) REFERENCES games(id) ON DELETE CASCADE;

@Zena0128 Zena0128 closed this as completed Nov 6, 2024
@Zena0128
Copy link
Contributor Author

Zena0128 commented Nov 6, 2024

잘 되는 줄 알았는데.... game progress 타임라인만 존재하면 잘 되는데
교체나 득점 타임라인 존재 시 여전히 오류나네용,,

@Zena0128 Zena0128 reopened this Nov 6, 2024
@Zena0128
Copy link
Contributor Author

Zena0128 commented Nov 6, 2024

교체, 득점 타임라인도 LineupPlayer와 갖는 fk 때문에 발생하는 오류여서
원래 있던 관련 제약조건들 다 drop 후

ALTER TABLE timelines
ADD CONSTRAINT FK_TIMELINES_ON_ORIGIN_LINEUP_PLAYER FOREIGN KEY (origin_lineup_player_id) REFERENCES lineup_players(id) ON DELETE CASCADE;

ALTER TABLE timelines
ADD CONSTRAINT FK_TIMELINES_ON_REPLACED_LINEUP_PLAYER FOREIGN KEY (replaced_lineup_player_id) REFERENCES lineup_players(id) ON DELETE CASCADE;

ALTER TABLE timeliness
ADD CONSTRAINT FK_TIMELINES_ON_SCORER FOREIGN KEY (scorere_id) REFERENCES lineup_players(id) ON DELETE CASCADE;

쿼리 실행하니 서비스 상에서는 잘 되어여
@OnDelete가 다 먹지 않았던 듯 합미당

다만 테스트코드에서는 자꾸 제약조건이 걸려 실패하는디... 아직 캐시때문에 제대로 업데이트가 안 된 것인지..? 확인 필요

@Zena0128
Copy link
Contributor Author

Zena0128 commented Nov 7, 2024

생각해보니 테스트코드는 테스트디비 위에서 돌아가서 그랬겠군여,,,
근데 테스트디비에 제약조건 어케 거는지는 잘 몰라서 회의 때 마저 얘기해보면 좋겠습니당 ㅠ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant