<?php
require_once 'db.php';

try {
    $msg = [];
    
    // Check if email column exists
    $stmt = $pdo->query("SHOW COLUMNS FROM users LIKE 'email'");
    if ($stmt->rowCount() == 0) {
        $pdo->exec("ALTER TABLE users ADD COLUMN email VARCHAR(150) UNIQUE DEFAULT NULL");
        $msg[] = "Kolom 'email' berhasil ditambahkan.";
    }
    
    // Check if google_id column exists
    $stmt = $pdo->query("SHOW COLUMNS FROM users LIKE 'google_id'");
    if ($stmt->rowCount() == 0) {
        $pdo->exec("ALTER TABLE users ADD COLUMN google_id VARCHAR(100) DEFAULT NULL");
        $msg[] = "Kolom 'google_id' berhasil ditambahkan.";
    }

    if (empty($msg)) {
        echo "Tabel users sudah up-to-date.";
    } else {
        echo implode("\n", $msg);
    }
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}
