<?php
require_once 'config/database.php';

echo "Attempting to add group_name column to students table...\n";

try {
    // Check if the column already exists
    $columns = $pdo->query("DESCRIBE students")->fetchAll(PDO::FETCH_COLUMN);
    
    if (in_array('group_name', $columns)) {
        echo "Group name column already exists.\n";
    } else {
        // Add the group_name column
        $pdo->exec("ALTER TABLE students ADD COLUMN group_name VARCHAR(50) AFTER session");
        echo "Group name column added successfully!\n";
    }
    
    // Also make sure session column exists
    if (!in_array('session', $columns)) {
        $pdo->exec("ALTER TABLE students ADD COLUMN session VARCHAR(20) AFTER class_id");
        echo "Session column added successfully!\n";
    }
    
    echo "Database update completed.\n";
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
?>