<?php
require_once 'config.php';
$conn = getDBConnection();
if (!$conn) {
    die("<h1>Connection Failed</h1>");
}
try {
    $conn->exec("ALTER TABLE mediciones 
        ADD COLUMN IF NOT EXISTS buque_id VARCHAR(50) AFTER id,
        ADD COLUMN IF NOT EXISTS temp1 DECIMAL(5,2),
        ADD COLUMN IF NOT EXISTS temp2 DECIMAL(5,2),
        ADD COLUMN IF NOT EXISTS temp3 DECIMAL(5,2),
        ADD COLUMN IF NOT EXISTS temp4 DECIMAL(5,2),
        ADD COLUMN IF NOT EXISTS temp5 DECIMAL(5,2),
        ADD COLUMN IF NOT EXISTS temp6 DECIMAL(5,2),
        ADD COLUMN IF NOT EXISTS temp7 DECIMAL(5,2),
        ADD COLUMN IF NOT EXISTS temp8 DECIMAL(5,2),
        ADD COLUMN IF NOT EXISTS temp9 DECIMAL(5,2),
        ADD COLUMN IF NOT EXISTS temp10 DECIMAL(5,2)");

    $conn->exec("UPDATE mediciones SET buque_id = 'BUQUE-01' WHERE buque_id IS NULL OR buque_id = ''");

    echo "<h1>Database Extension (v2) Successful</h1>";
} catch (Exception $e) {
    echo "<h1>Error</h1><pre>" . $e->getMessage() . "</pre>";
}
?>