WorkspaceEngagementSurvey 마이그레이션 + 모델 + DiagnosisSession 확장

ID: b97ac168-f50f-4ddd-9ac0-0d953a561c2d

높음 할 일

## 작업 내용

### 1. 마이그레이션: create_workspace_engagement_surveys
```
- id: uuid, primary_key
- workspace_id: uuid, NOT NULL, FK(workspaces), index
- created_by_id: uuid, NOT NULL, FK(users)
- title: string, NOT NULL (예: "2026 Q1")
- year: integer, NOT NULL
- quarter: integer, NOT NULL (1-4)
- status: integer, NOT NULL, default: 0 (enum: draft=0, active=1, closed=2)
- access_token: string, NOT NULL, unique index
- started_at: datetime
- ended_at: datetime
- timestamps
- 복합 unique 인덱스: [workspace_id, year, quarter]
```

### 2. 마이그레이션: add_engagement_survey_to_diagnosis_sessions
```
- workspace_engagement_survey_id: uuid, FK(workspace_engagement_surveys), index (nullable)
- workspace_group_id: uuid, FK(workspace_groups), index (nullable)
```

### 3. WorkspaceEngagementSurvey 모델
- belongs_to :workspace
- belongs_to :created_by, class_name: "User"
- has_many :diagnosis_sessions (workspace_engagement_survey_id)
- enum :status, { draft: 0, active: 1, closed: 2 }
- validates: workspace, title, year, quarter, access_token presence
- validates: quarter, inclusion: 1..4
- validates: [workspace_id, year, quarter] uniqueness (scope)
- before_validation: access_token 자동 생성 (SecureRandom.alphanumeric(8).upcase)
- scope :for_workspace → where(workspace_id:)
- scope :active → where(status: :active)
- scope :by_period → order(year: :desc, quarter: :desc)

### 4. DiagnosisSession 확장
- belongs_to :workspace_engagement_survey, optional: true
- belongs_to :workspace_group, class_name: "WorkspaceGroup", optional: true

### 5. Workspace 모델 확장
- has_many :engagement_surveys, class_name: "WorkspaceEngagementSurvey"

### 6. fixture 생성
- test/fixtures/workspace_engagement_surveys.yml (2~3개)

### 7. 테스트
- test/models/workspace_engagement_survey_test.rb
- 유효성 검사 (필수 필드, quarter 범위, uniqueness)
- 연관관계
- enum
- access_token 자동 생성
- 스코프
- DiagnosisSession 연관관계 테스트

## 중요 사항
- 모든 rails 명령은 `docker compose exec web` 으로 실행
- TDD: 테스트 먼저 작성 → 구현
- DB 안전: test 환경에서만 마이그레이션 테스트

첨부 이미지

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

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

담당자: developer-1
생성일: 2026년 03월 17일 08:06

활동 로그

아직 활동 기록이 없습니다.