<?php

declare(strict_types=1);

require dirname(__DIR__) . '/bootstrap.php';

use Core\Database;

if (!in_array('--force', $argv, true)) {
    echo "Este script altera a tabela admin_users. Rode com --force para continuar.\n";
    exit(1);
}

$pdo = Database::connection();
$exists = (bool) $pdo->query("SHOW COLUMNS FROM admin_users LIKE 'role'")->fetch();

if (!$exists) {
    $pdo->exec("ALTER TABLE admin_users ADD COLUMN role VARCHAR(20) NOT NULL DEFAULT 'admin' AFTER password_hash");
    $pdo->exec("UPDATE admin_users SET role = 'admin' WHERE role IS NULL OR role = ''");
    echo "Coluna role criada com sucesso em admin_users.\n";
} else {
    echo "Coluna role já existe em admin_users.\n";
}
