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

try {
    echo "Adding created_by column to expenses table...\n";
    
    // Add the missing column
    $pdo->exec("ALTER TABLE expenses ADD COLUMN created_by INT NULL AFTER receipt_no");
    
    echo "Column added successfully!\n";
    
    // Verify the column exists
    $stmt = $pdo->query("DESCRIBE expenses");
    $columns = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    $column_names = array_column($columns, 'Field');
    if (in_array('created_by', $column_names)) {
        echo "Verification: created_by column exists in expenses table\n";
    } else {
        echo "Error: created_by column was not added\n";
    }
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
?>