<?php
/**
 * Migration script to add allow_direct_deposit column to accounts table
 */

try {
    $dsn = "mysql:host=localhost;dbname=naveed_trader_db;charset=utf8mb4";
    $db = new PDO($dsn, "root", "", [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4"
    ]);

    echo "Connected to database.\n";

    // Check if column already exists
    $stmt = $db->query("SHOW COLUMNS FROM accounts LIKE 'allow_direct_deposit'");
    $column = $stmt->fetch();

    if ($column) {
        echo "Column 'allow_direct_deposit' already exists. Skipping migration.\n";
    } else {
        echo "Adding column 'allow_direct_deposit' to accounts table...\n";
        $db->exec("ALTER TABLE accounts ADD COLUMN allow_direct_deposit TINYINT(1) DEFAULT 0 COMMENT '1 = allow direct capital deposit, 0 = do not allow'");
        echo "Column added successfully.\n";
    }

    echo "\nSUCCESS! Migration completed.\n";

} catch (PDOException $e) {
    echo "ERROR: " . $e->getMessage() . "\n";
}
