<?php
/**
 * Run migrations to add PAN, Aadhar, and Remarks columns to employees table
 * Run this file once to add the required columns
 */

require_once __DIR__ . '/../../includes/init.php';

try {
    $db = getDB();
    
    echo "Starting migrations...\n\n";
    
    // Check if pan_number column exists
    $stmt = $db->query("SHOW COLUMNS FROM employees LIKE 'pan_number'");
    if ($stmt->rowCount() == 0) {
        echo "Adding pan_number column...\n";
        $db->exec("ALTER TABLE `employees` ADD COLUMN `pan_number` varchar(50) AFTER `uan_number`");
        echo "✓ pan_number column added successfully\n";
    } else {
        echo "✓ pan_number column already exists\n";
    }
    
    // Check if aadhar_number column exists
    $stmt = $db->query("SHOW COLUMNS FROM employees LIKE 'aadhar_number'");
    if ($stmt->rowCount() == 0) {
        echo "Adding aadhar_number column...\n";
        $db->exec("ALTER TABLE `employees` ADD COLUMN `aadhar_number` varchar(50) AFTER `pan_number`");
        echo "✓ aadhar_number column added successfully\n";
    } else {
        echo "✓ aadhar_number column already exists\n";
    }
    
    // Check if remarks column exists
    $stmt = $db->query("SHOW COLUMNS FROM employees LIKE 'remarks'");
    if ($stmt->rowCount() == 0) {
        echo "Adding remarks column...\n";
        $db->exec("ALTER TABLE `employees` ADD COLUMN `remarks` text AFTER `aadhar_number`");
        echo "✓ remarks column added successfully\n";
    } else {
        echo "✓ remarks column already exists\n";
    }
    
    echo "\nAll migrations completed successfully!\n";
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
    exit(1);
}

