[client] tb_client.scopes 정규화 및 삭제 정합성 보장#307
Open
wwwcomcomcomcom wants to merge 5 commits intodevelopfrom
Open
[client] tb_client.scopes 정규화 및 삭제 정합성 보장#307wwwcomcomcomcom wants to merge 5 commits intodevelopfrom
wwwcomcomcomcom wants to merge 5 commits intodevelopfrom
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request migrates OAuth scope storage from a text field to a dedicated collection table using @ElementCollection. Key updates include adding native delete queries to ClientJpaRepository, updating QueryDSL fetch joins, and implementing scope cleanup in deletion services. Review feedback recommends optimizing read performance with JSON serialization, using val for collection properties per the style guide, and refining collection updates while noting that scope-related logic in the web module is slated for future removal.
...common/src/main/kotlin/team/themoment/datagsm/common/domain/client/entity/ClientJpaEntity.kt
Show resolved
Hide resolved
...common/src/main/kotlin/team/themoment/datagsm/common/domain/client/entity/ClientJpaEntity.kt
Outdated
Show resolved
Hide resolved
...main/kotlin/team/themoment/datagsm/web/domain/client/service/impl/CreateClientServiceImpl.kt
Outdated
Show resolved
Hide resolved
snowykte0426
approved these changes
Apr 8, 2026
Member
snowykte0426
left a comment
There was a problem hiding this comment.
전체적으로 괜찮은 것 같은데 Client뿐 아니라 API키 조회 부분도 정규화를 진행해 일관성을 맞추는게 어떠할까요?
그리고 DB 마이그레이션 스크립트도 작성 부탁드리겠습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
개요
tb_client.scopesJSON 텍스트 컬럼을tb_client_scope조인 테이블로 정규화하고,Application및OAuthScope삭제 시 Client의 scope 참조가 정리되지 않던 문제를 해결하였습니다.본문
문제
ClientJpaEntity.scopes가StringSetConverter를 통해 JSON 배열 텍스트(["appId:scopeName", ...])로 저장되어 있어 다음 문제가 발생하였습니다:OAuthScope삭제 시tb_client에 삭제된 scope 문자열이 잔존Application삭제 시 해당 application의 모든 scope 문자열이 잔존Oauth2TokenServiceImpl.stringsToScopes()에서 삭제된 scope를 만나면 500 에러 발생변경 내용
정규화
ClientJpaEntity.scopes를@ElementCollection+@CollectionTable("tb_client_scope")로 변경하였습니다.@OnDelete(action = OnDeleteAction.CASCADE)를 적용하여 Client 삭제 시 DB 레벨에서 scope 행이 자동 삭제됩니다.FetchType.EAGER를 설정하여 Client 조회 시 scopes가 항상 함께 로딩됩니다.삭제 정합성
DeleteOAuthScopeServiceImpl에서 scope 삭제 전removeScopeFromClients()를 호출하여 해당 scope를 참조하는 Client를 정리합니다.DeleteApplicationServiceImpl에서 Application 삭제 전removeScopesByApplicationId()를 호출하여 관련 scope를 일괄 정리합니다.tb_client_scope.scope인덱스를 활용하는 네이티브 쿼리로 구현하였습니다.QueryDSL fetch join
ClientJpaCustomRepositoryImpl의 목록 조회 쿼리에leftJoin(clientJpaEntity.scopes).fetchJoin()을 추가하여 추가 SELECT 없이 한 번의 쿼리로 scopes를 로딩합니다.DB 마이그레이션
tb_client_scope테이블을 추가해야합니다. 기존tb_client.scopes컬럼의 데이터를 새 테이블로 이관해야 합니다.추가 리뷰 요청
삭제시 정합성 유지를 위해 full table search가 불가피하여 이러한 변경을 하게 되었는데, client 도메인은 읽기가 훨씬 더 자주 일어나다보니 적합한 trade off 인지 고민입니다. 다른 방법이 있다면 생각 공유해주시길 바랍니다. ex) json을 지원하는 다른 db 사용