# Notification DB 체크 제약 조건 수정 가이드 ## 🚨 문제 상황 ``` ERROR: new row for relation "notifications" violates check constraint "notifications_notification_type_check" ``` Event Hub에서 메시지는 정상적으로 수신되지만, 데이터베이스 저장 시 체크 제약 조건 위반으로 실패 ## ✅ 해결 방법 ### 방법 1: Azure Portal 사용 (권장) 1. **Azure Portal 접속** - https://portal.azure.com 접속 2. **PostgreSQL 서버 찾기** - 리소스 검색에서 "4.230.159.143" 또는 "notificationdb" 검색 3. **Query Editor 열기** - 좌측 메뉴에서 "Query editor (preview)" 선택 - 사용자명: `hgzerouser` - 비밀번호: `Hi5Jessica!` - 데이터베이스: `notificationdb` 4. **SQL 실행** ```sql -- 기존 제약 조건 삭제 ALTER TABLE notifications DROP CONSTRAINT IF EXISTS notifications_notification_type_check; -- 새로운 제약 조건 추가 ALTER TABLE notifications ADD CONSTRAINT notifications_notification_type_check CHECK (notification_type IN ( 'MEETING_INVITATION', 'TODO_ASSIGNED', 'TODO_REMINDER', 'MEETING_REMINDER', 'MINUTES_UPDATED', 'TODO_COMPLETED' )); ``` 5. **확인** ```sql SELECT constraint_name, check_clause FROM information_schema.check_constraints WHERE constraint_name = 'notifications_notification_type_check'; ``` --- ### 방법 2: DB 관리 도구 사용 #### DBeaver 사용 1. DBeaver 다운로드: https://dbeaver.io/download/ 2. 새 연결 생성: - Host: `4.230.159.143` - Port: `5432` - Database: `notificationdb` - Username: `hgzerouser` - Password: `Hi5Jessica!` 3. SQL Editor에서 위의 SQL 실행 #### pgAdmin 사용 1. pgAdmin 다운로드: https://www.pgadmin.org/download/ 2. 서버 등록 후 Query Tool에서 SQL 실행 --- ### 방법 3: psql 직접 설치 (Mac/Linux) ```bash # Mac (Homebrew) brew install postgresql@15 # 실행 PGPASSWORD='Hi5Jessica!' psql -h 4.230.159.143 -p 5432 -U hgzerouser -d notificationdb -f notification/fix_constraint.sql ``` --- ### 방법 4: Python 스크립트 사용 ```bash # psycopg2 설치 pip install psycopg2-binary # 스크립트 실행 python3 notification/fix_db_constraint.py ``` --- ## 📋 실행할 SQL 생성된 파일: `notification/fix_constraint.sql` ```sql -- 기존 제약 조건 삭제 ALTER TABLE notifications DROP CONSTRAINT IF EXISTS notifications_notification_type_check; -- 새로운 제약 조건 추가 (Java Enum의 모든 값 포함) ALTER TABLE notifications ADD CONSTRAINT notifications_notification_type_check CHECK (notification_type IN ( 'MEETING_INVITATION', -- 회의 초대 'TODO_ASSIGNED', -- Todo 할당 'TODO_REMINDER', -- Todo 리마인더 'MEETING_REMINDER', -- 회의 리마인더 'MINUTES_UPDATED', -- 회의록 수정 'TODO_COMPLETED' -- Todo 완료 )); ``` --- ## 🔍 검증 방법 ### 1. 제약 조건 확인 ```sql SELECT constraint_name, check_clause FROM information_schema.check_constraints WHERE constraint_name = 'notifications_notification_type_check'; ``` ### 2. 서비스 재시작 후 로그 확인 ```bash # notification 서비스 재시작 cd notification ./gradlew bootRun # 로그 모니터링 tail -f logs/notification-service.log | grep -E "ERROR|이벤트 수신|알림 발송" ``` ### 3. 에러가 사라졌는지 확인 이 에러가 더 이상 나타나지 않아야 합니다: ``` ERROR: new row for relation "notifications" violates check constraint "notifications_notification_type_check" ``` --- ## 📌 참고 ### Java Enum 정의 위치 `notification/src/main/java/com/unicorn/hgzero/notification/domain/Notification.java:220-227` ```java public enum NotificationType { MEETING_INVITATION, // 회의 초대 TODO_ASSIGNED, // Todo 할당 TODO_REMINDER, // Todo 리마인더 MEETING_REMINDER, // 회의 리마인더 MINUTES_UPDATED, // 회의록 수정 TODO_COMPLETED // Todo 완료 } ``` ### 현재 상태 - ✅ Event Hub 연결: 정상 - ✅ 메시지 수신: 정상 - ✅ 이메일 발송: 정상 - ❌ DB 저장: 제약 조건 위반으로 실패 ← **해결 필요** --- ## ⚠️ 주의사항 - 프로덕션 환경이라면 백업 먼저 수행 - 테스트 환경에서 먼저 검증 후 프로덕션 적용 - SQL 실행 권한이 필요합니다