-- schedule_entries 확장: 작업보고서 매핑 + 위험성평가 연결 + 생성 출처
ALTER TABLE schedule_entries ADD COLUMN work_type_id INT NULL COMMENT 'work_types FK (작업보고서 매핑)';

ALTER TABLE schedule_entries ADD COLUMN risk_assessment_id INT NULL COMMENT 'risk_projects FK';

ALTER TABLE schedule_entries ADD COLUMN source VARCHAR(20) DEFAULT 'manual' COMMENT '생성 출처 (manual/template)';

-- schedule_phases 확장: 제품유형별 phase 구분
ALTER TABLE schedule_phases ADD COLUMN product_type_id INT NULL COMMENT 'NULL=범용, 값=해당 제품유형 전용';

-- FK는 product_types 테이블 존재 시에만 생성 (tkuser 마이그레이션 의존)
-- work_type_id FK
ALTER TABLE schedule_entries ADD CONSTRAINT fk_entry_work_type
  FOREIGN KEY (work_type_id) REFERENCES work_types(id) ON DELETE SET NULL;

-- risk_assessment_id FK (같은 DB, 물리 FK)
ALTER TABLE schedule_entries ADD CONSTRAINT fk_entry_risk_assessment
  FOREIGN KEY (risk_assessment_id) REFERENCES risk_projects(id) ON DELETE SET NULL;

-- schedule_phases.product_type_id FK
ALTER TABLE schedule_phases ADD CONSTRAINT fk_phase_product_type
  FOREIGN KEY (product_type_id) REFERENCES product_types(id) ON DELETE SET NULL
