You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
알림(Notification) 도메인에서 타입별로 다른 속성을 어떻게 테이블에 반영할 것인가에 대한 설계 논의.
특히 NotificationType 중 SUGGESTION 타입만 recommendedTargetAmount 와 applyTargetAmount 속성을 가지며,
NOTICE, REMINDER 타입은 해당 속성이 필요하지 않음.
즉, 공통 속성과 특정 타입 전용 속성을 어떻게 모델링할지가 핵심 주제.
대안 1: 단일 테이블(Nullable 허용)
스키마
CREATETABLEnotification (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
notification_type VARCHAR(20) NOT NULL,
content VARCHAR(255) NOT NULL,
is_read BOOLEANNOT NULL,
created_at DATETIME NOT NULL,
member_id BIGINTNOT NULL,
recommended_target_amount INTNULL,
apply_target_amount BOOLEANNULL
);
특성
데이터 모델: 모든 타입 공용 컬럼. SUGGESTION 전용 컬럼 2개는 NULL 허용.
무결성: 타입별 제약(“SUGGESTION이면 두 컬럼 NOT NULL”)을 DB 레벨에서 강제 불가. 애플리케이션 검증 필요.
쿼리: 단건/리스트 조회 모두 단일 테이블 스캔. 조인 없음.
성능: 단순. 인덱스 설계 용이. 스토리지 상 “희소 컬럼”으로 NULL 빈도 증가 가능.
JPA 매핑: 단일 엔티티. @column(nullable=true)로 표현. 도메인 제약은 서비스/밸리데이터에서 처리.
마이그레이션: 쉬움. 컬럼 추가/삭제만으로 대응.
테스트: 타입별 유효성 테스트는 서비스/도메인 레벨에 집중.
운영: 스키마 단순. 타입 추가 시 NULL 컬럼 증가 가능.
엣지: 잘못된 타입-컬럼 조합이 DB에 저장될 여지 존재(애플리케이션 버그 시).
⸻
대안 2: 상속 분리(JOINED)
스키마
CREATETABLEnotification (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
notification_type VARCHAR(20) NOT NULL,
content VARCHAR(255) NOT NULL,
is_read BOOLEANNOT NULL,
created_at DATETIME NOT NULL,
member_id BIGINTNOT NULL
);
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
주제
알림(Notification) 도메인에서 타입별로 다른 속성을 어떻게 테이블에 반영할 것인가에 대한 설계 논의.
특히 NotificationType 중 SUGGESTION 타입만 recommendedTargetAmount 와 applyTargetAmount 속성을 가지며,
NOTICE, REMINDER 타입은 해당 속성이 필요하지 않음.
즉, 공통 속성과 특정 타입 전용 속성을 어떻게 모델링할지가 핵심 주제.
대안 1: 단일 테이블(Nullable 허용)
스키마
특성
⸻
대안 2: 상속 분리(JOINED)
스키마
특성
Beta Was this translation helpful? Give feedback.
All reactions