require_once '../config/database.php';

try {
    echo "Checking 'youtube_manual_logs'...\n";
    $stmt = $pdo->query("SHOW COLUMNS FROM youtube_manual_logs LIKE 'physical_attendance'");
    $col = $stmt->fetch();
    
    if ($col) {
        echo "Column 'physical_attendance' ALREADY EXISTS.\n";
    } else {
        echo "Column MISSING. Attempting to add...\n";
        $pdo->exec("ALTER TABLE youtube_manual_logs ADD COLUMN `physical_attendance` INT DEFAULT 0");
        echo "Added 'physical_attendance'.\n";
    }

    $stmt = $pdo->query("SHOW COLUMNS FROM youtube_manual_logs LIKE 'service_type'");
    if ($stmt->fetch()) {
        echo "Column 'service_type' ALREADY EXISTS.\n";
    } else {
         echo "Column 'service_type' MISSING. Attempting to add...\n";
        $pdo->exec("ALTER TABLE youtube_manual_logs ADD COLUMN `service_type` VARCHAR(100) DEFAULT 'General'");
         echo "Added 'service_type'.\n";
    }
    
    echo "Checking 'radio_manual_logs'...\n";
    $stmt = $pdo->query("SHOW COLUMNS FROM radio_manual_logs LIKE 'service_type'");
    if ($stmt->fetch()) {
        echo "Radio 'service_type' ALREADY EXISTS.\n";
    } else {
        echo "Radio 'service_type' MISSING. Attempting to add...\n";
         $pdo->exec("ALTER TABLE radio_manual_logs ADD COLUMN `service_type` VARCHAR(100) DEFAULT 'General' AFTER `service_date`");
         echo "Added Radio 'service_type'.\n";
    }

    echo "DONE.\n";

} catch (PDOException $e) {
    echo "PDO Error: " . $e->getMessage() . "\n";
} catch (Exception $e) {
    echo "General Error: " . $e->getMessage() . "\n";
}
