<?php
require_once 'config.php';

$conn = getDBConnection();

// Check if event_type column exists
$result = $conn->query("SHOW COLUMNS FROM events LIKE 'event_type'");

if ($result->num_rows === 0) {
    // Add event_type column
    $sql = "ALTER TABLE events ADD COLUMN event_type VARCHAR(50) NOT NULL DEFAULT 'Other' AFTER event_name";
    
    if ($conn->query($sql) === TRUE) {
        echo "Added event_type column to events table successfully!<br>";
        
        // Add index
        $conn->query("ALTER TABLE events ADD INDEX idx_event_type (event_type)");
        
        echo "Migration completed successfully!<br>";
    } else {
        echo "Error: " . $conn->error . "<br>";
    }
} else {
    echo "Events table already has event_type column. No migration needed.<br>";
}

$conn->close();
echo "<br><strong>Migration completed!</strong><br>";
echo "<a href='home.php'>Go to Home</a>";
?>

