<?php

require_once __DIR__ . '/../vendor/autoload.php';

use App\Config\Database;

try {
    $conn = Database::getInstance()->getConnection();

    echo "Adicionando coluna 'last_seen' na tabela 'servers'...\n";

    // Check if column exists
    $stmt = $conn->query("SHOW COLUMNS FROM servers LIKE 'last_seen'");
    if ($stmt->rowCount() == 0) {
        $sql = "ALTER TABLE servers ADD COLUMN last_seen TIMESTAMP NULL DEFAULT NULL AFTER status";
        $conn->exec($sql);
        echo "Coluna 'last_seen' adicionada com sucesso.\n";
    } else {
        echo "Coluna 'last_seen' já existe.\n";
    }

} catch (Exception $e) {
    echo "Erro: " . $e->getMessage() . "\n";
    exit(1);
}
