<?php
include_once __DIR__ . '/config/database.php';

try {
    $db = new Database();
    $conn = $db->getConnection();
    
    $queries = [
        "ALTER TABLE transactions MODIFY COLUMN account_id INT NULL",
        "ALTER TABLE transactions ADD COLUMN sender_id INT NULL AFTER account_id",
        "ALTER TABLE transactions ADD COLUMN receiver_id INT NULL AFTER sender_id",
        "ALTER TABLE transactions ADD COLUMN transaction_id VARCHAR(50) NULL AFTER id",
        "ALTER TABLE transactions MODIFY COLUMN type VARCHAR(50) NOT NULL",
        "ALTER TABLE transactions MODIFY COLUMN status VARCHAR(50) NOT NULL"
    ];
    
    foreach ($queries as $q) {
        try {
            $conn->exec($q);
            echo "Success: $q\n";
        } catch (Exception $e) {
            echo "Notice (maybe already applied): " . $e->getMessage() . "\n";
        }
    }
    echo "Transactions schema patch complete.\n";
    
} catch (Exception $e) {
    echo "Connection failed: " . $e->getMessage();
}
?>
