<?php
require_once 'config.php';
$pdo = getDBConnection();

if ($pdo) {
    try {
        echo "Updating ships table schema...\n";

        // Add last_contact column
        $pdo->exec("ALTER TABLE ships ADD COLUMN IF NOT EXISTS last_contact DATETIME DEFAULT NULL");
        echo "Added 'last_contact' column.\n";

        // Add last_payload column (JSON type)
        $pdo->exec("ALTER TABLE ships ADD COLUMN IF NOT EXISTS last_payload LONGTEXT DEFAULT NULL");
        echo "Added 'last_payload' column.\n";

        // Add min_temp column
        $pdo->exec("ALTER TABLE ships ADD COLUMN IF NOT EXISTS min_temp DECIMAL(5,2) DEFAULT 0.00");
        echo "Added 'min_temp' column.\n";

        echo "Schema update completed successfully.\n";
    } catch (PDOException $e) {
        echo "Error updating schema: " . $e->getMessage() . "\n";
    }
} else {
    echo "Database connection failed.\n";
}
?>