-- =====================================================
-- daily_attendance_records 테이블 운영 DB 동기화
-- 실행 전 백업 권장
-- =====================================================

-- 1. is_present 컬럼 추가 (출근 체크용)
ALTER TABLE `daily_attendance_records`
ADD COLUMN IF NOT EXISTS `is_present` TINYINT(1) DEFAULT 1 COMMENT '출근 여부' AFTER `is_overtime_approved`;

-- 기존 데이터는 모두 출근으로 설정
UPDATE `daily_attendance_records` SET `is_present` = 1 WHERE `is_present` IS NULL;

-- 2. created_by 컬럼 추가 (등록자)
ALTER TABLE `daily_attendance_records`
ADD COLUMN IF NOT EXISTS `created_by` INT NULL COMMENT '등록자 user_id' AFTER `is_present`;

-- 기존 데이터는 시스템(1)으로 설정
UPDATE `daily_attendance_records` SET `created_by` = 1 WHERE `created_by` IS NULL;

-- 3. check_in_time, check_out_time 컬럼 추가 (선택사항)
ALTER TABLE `daily_attendance_records`
ADD COLUMN IF NOT EXISTS `check_in_time` TIME NULL COMMENT '출근 시간' AFTER `vacation_type_id`;

ALTER TABLE `daily_attendance_records`
ADD COLUMN IF NOT EXISTS `check_out_time` TIME NULL COMMENT '퇴근 시간' AFTER `check_in_time`;

-- 4. notes 컬럼 추가
ALTER TABLE `daily_attendance_records`
ADD COLUMN IF NOT EXISTS `notes` TEXT NULL COMMENT '비고' AFTER `is_overtime_approved`;

-- =====================================================
-- 확인용 쿼리
-- =====================================================
-- DESCRIBE `daily_attendance_records`;
