-- ============================================================
-- 업무현황 다건 입력 + 작업자 시간 추적 마이그레이션
-- 실행: MariaDB (tkpurchase DB)
-- 날짜: 2026-03-13
-- ============================================================

-- 1) 유니크 제약 제거 (1일정-1보고 제한 해제)
ALTER TABLE partner_work_reports DROP INDEX uq_pwr_schedule_report_date;

-- 2) 보고 순번 컬럼 추가
ALTER TABLE partner_work_reports
  ADD COLUMN report_seq TINYINT NOT NULL DEFAULT 1 AFTER report_date;

-- 3) 작업자별 투입시간 테이블
CREATE TABLE IF NOT EXISTS work_report_workers (
  id                INT AUTO_INCREMENT PRIMARY KEY,
  report_id         INT NOT NULL,
  partner_worker_id INT,
  worker_name       VARCHAR(100) NOT NULL,
  hours_worked      DECIMAL(4,1) DEFAULT 8.0,
  created_at        TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  CONSTRAINT fk_wrw_report FOREIGN KEY (report_id)
    REFERENCES partner_work_reports(id) ON DELETE CASCADE,
  CONSTRAINT fk_wrw_partner_worker FOREIGN KEY (partner_worker_id)
    REFERENCES partner_workers(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
