<?php
require_once __DIR__ . '/../src/Utils/Env.php';
require_once __DIR__ . '/../src/Config/Database.php';

use App\Utils\Env;
use App\Config\Database;

Env::load(__DIR__ . '/../../.env');
$db = Database::getInstance()->getConnection();

try {
    // 1. Add is_anonymous to conversations if not exists
    $db->exec("ALTER TABLE conversations ADD COLUMN is_anonymous TINYINT(1) DEFAULT 0");
    echo "Migration successful: Added is_anonymous to conversations.<br>";
} catch (PDOException $e) {
    echo "Migration info (conversations): " . $e->getMessage() . "<br>";
}

try {
    // 2. Add sender_alias and is_anonymous to messages if not exists
    $db->exec("ALTER TABLE messages ADD COLUMN sender_alias VARCHAR(50) NULL");
    $db->exec("ALTER TABLE messages ADD COLUMN is_anonymous TINYINT(1) DEFAULT 0");
    echo "Migration successful: Added message columns.<br>";
} catch (PDOException $e) {
    echo "Migration info (messages): " . $e->getMessage() . "<br>";
}
