<?php
// api/upgrade_db.php - 資料庫時間擴充手術
header("Content-Type: text/html; charset=utf-8");
require_once 'db.php';

try {
    // 幫 tasks 資料表加上 duration (秒數) 欄位
    $sql = "ALTER TABLE tasks ADD COLUMN duration INT DEFAULT 20 COMMENT '任務秒數' AFTER target_url";
    $pdo->exec($sql);
    echo "<h2 style='color:#00ff88; background:#111; padding:20px;'>✅ 手術成功！『duration (任務秒數)』欄位已加入資料庫！</h2>";
} catch (PDOException $e) {
    if (strpos($e->getMessage(), "Duplicate column") !== false) {
        echo "<h2 style='color:#00ced1; background:#111; padding:20px;'>✅ 欄位已經存在，系統安然無恙，請繼續下一步！</h2>";
    } else {
        echo "<h2 style='color:red;'>❌ 錯誤：" . $e->getMessage() . "</h2>";
    }
}
?>