-- Fix attendance_periods table - Add AUTO_INCREMENT to period_id
-- Run this in phpMyAdmin

-- Step 1: Check current structure
DESCRIBE attendance_periods;

-- Step 2: Fix period_id AUTO_INCREMENT
ALTER TABLE attendance_periods MODIFY COLUMN `period_id` int(11) NOT NULL AUTO_INCREMENT;

-- Step 3: Verify the fix
DESCRIBE attendance_periods;

-- ============================================
-- IF ABOVE DOESN'T WORK, USE THIS ALTERNATIVE:
-- ============================================

-- Option A: Drop and recreate table (WARNING: Deletes all data)
-- Only use if table is empty or you have backup

/*
DROP TABLE IF EXISTS attendance_periods;

CREATE TABLE `attendance_periods` (
  `period_id` int(11) NOT NULL AUTO_INCREMENT,
  `site_id` int(11) NOT NULL,
  `attendance_month` varchar(20) NOT NULL,
  `period_display` varchar(50) DEFAULT NULL,
  `employee_count` int(11) DEFAULT 0,
  `is_finalized` tinyint(1) DEFAULT 0,
  `finalized_at` datetime DEFAULT NULL,
  `finalized_by` int(11) DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`period_id`),
  UNIQUE KEY `unique_site_month` (`site_id`, `attendance_month`),
  KEY `idx_site_id` (`site_id`),
  KEY `idx_attendance_month` (`attendance_month`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
*/
