<?php
require_once 'config/db.php';
$log = [];
$alters = [
    "ALTER TABLE sales_agents ADD COLUMN username      VARCHAR(80)  NULL DEFAULT NULL AFTER designation",
    "ALTER TABLE sales_agents ADD COLUMN password_hash VARCHAR(255) NULL DEFAULT NULL AFTER username",
    "ALTER TABLE sales_agents ADD UNIQUE INDEX idx_agent_username (username)",
];
foreach ($alters as $sql) {
    try { $pdo->exec($sql); $log[] = "✅ $sql"; }
    catch(PDOException $e) {
        $msg = $e->getMessage();
        $log[] = (strpos($msg,'Duplicate')!==false||strpos($msg,'already exists')!==false) ? "⚠️  Already exists — skipped." : "❌ $msg";
    }
}
foreach ($log as $l) echo "<p>$l</p>";
echo "<p><strong>Done! <a href='sales_agents.php'>Go to Sales Agents →</a></strong></p>";
?>
