알림 기반: Gem 추가 + PushSubscription 모델 + 마이그레이션

ID: d9674ebd-1c99-4083-a99f-71876d6907e2

높음 완료

## 목표
알림 시스템의 DB 기반을 구축합니다.

## 작업 내용

### 1. Gemfile에 web-push gem 추가
```ruby
gem "web-push"
```
- `bundle install` 실행

### 2. PushSubscription 모델 + 마이그레이션 생성
```bash
bin/rails generate model PushSubscription \
user:references \
endpoint:string \
p256dh:string \
auth:string \
is_active:boolean \
browser_info:string \
device_info:string \
last_notification_sent:datetime
```
- 마이그레이션 파일 수정:
- `id: :string` (UUID PK)
- `user_id`는 `type: :string` (UUID FK)
- `is_active` default: true
- `endpoint` NOT NULL
- `p256dh`, `auth` NOT NULL
- unique index: `[:user_id, :endpoint]`
- 레거시에서는 subscription을 JSONB로 저장했지만, SQLite3에서는 endpoint/p256dh/auth를 개별 칼럼으로 분리

### 3. user_settings에 notification_methods 칼럼 추가
```bash
bin/rails generate migration AddNotificationMethodsToUserSettings notification_methods:string
```
- default: "push" (콤마 구분 문자열: "push,email,kakao")
- SQLite3에서 배열 타입 미지원이므로 string으로 저장

### 4. 모델 코드
**PushSubscription 모델:**
```ruby
class PushSubscription < ApplicationRecord
belongs_to :user

validates :endpoint, presence: true, uniqueness: { scope: :user_id }
validates :p256dh, presence: true
validates :auth, presence: true

scope :active, -> { where(is_active: true) }
scope :by_device, ->(type) { where("device_info LIKE ?", "%#{type}%") if type.present? }
end
```

**User 모델 업데이트:**
- `has_many :push_subscriptions, dependent: :destroy` 추가

**UserSetting 모델 업데이트:**
- notification_methods 관련 헬퍼 메서드 추가:
```ruby
def notification_methods_array
(notification_methods || "push").split(",")
end

def push_enabled?
notification_methods_array.include?("push")
end

def email_enabled?
notification_methods_array.include?("email")
end

def kakao_enabled?
notification_methods_array.include?("kakao")
end
```

### 5. 마이그레이션 실행
```bash
bin/rails db:migrate
```

### 6. 테스트 실행
```bash
bin/rails test
```

## 완료 기준
- web-push gem 설치됨
- push_subscriptions 테이블 생성됨 (UUID PK)
- user_settings에 notification_methods 칼럼 존재
- User has_many :push_subscriptions 관계 설정됨
- bin/rails test 통과

첨부 이미지

이미지 추가 (Ctrl+V로 붙여넣기 또는 클릭)

JPEG, PNG, GIF, WebP / 최대 10MB

담당자: notification-foundation
생성일: 2026년 03월 02일 04:40

활동 로그

  • 팀리드 상태 변경: 리뷰 → 완료

    2026년 03월 02일 05:13:02

  • N
    notification-foundation 상태 변경: 할 일 → 리뷰

    2026년 03월 02일 04:54:47

  • N
    notification-foundation 알림 기반 구축 완료 - web-push gem + PushSubscription 모델 + 마이그레이션

    2026년 03월 02일 04:54:46

    상세 보기

    ## 수정된 파일

    ### Gemfile / Gemfile.lock
    - `gem "web-push"` 추가 (v3.1.0)
    - Dockerfile에 libssl-dev 추가 (openssl 빌드 의존성)

    ### 마이그레이션
    - `db/migrate/20260302150001_create_push_subscriptions.rb` - PushSubscription 테이블 (UUID PK, user_id FK, endpoint/p256dh/auth NOT NULL, unique index [user_id, endpoint])
    - `db/migrate/20260302150002_add_notification_methods_to_user_settings.rb` - notification_methods 칼럼 (default: "push")

    ### 모델
    - `app/models/push_subscription.rb` - belongs_to :user, validates, scope :active
    - `app/models/user.rb` - has_many :push_subscriptions, dependent: :destroy 추가
    - `app/models/user_setting.rb` - notification_methods_array, push_enabled?, email_enabled?, kakao_enabled? 메서드 추가

    ### 테스트 (28 tests, 52 assertions, 0 failures)
    - `test/models/push_subscription_test.rb` - 12 tests (연관, 유효성, 스코프, cascade delete)
    - `test/models/user_setting_test.rb` - 7 notification tests 추가 (기존 9 + 7 = 16)
    - `test/fixtures/push_subscriptions.yml` - daniel_chrome, admin_chrome

    ### Docker
    - `Dockerfile` - build stage에 libssl-dev 추가
    - `compose.yaml` - 포트 3001:3000 (nineway와 충돌 회피)

  • N
    notification-foundation 알림 기반 구축 작업 시작

    2026년 03월 02일 04:42:31

    상세 보기

    ## 작업 범위
    - web-push gem 추가
    - PushSubscription 모델 + 마이그레이션 생성
    - user_settings에 notification_methods 칼럼 추가
    - 테스트 통과 확인