<?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();

echo "<pre>\n";

try {
    $db->exec("ALTER TABLE reports ADD COLUMN conversation_id BIGINT UNSIGNED NULL AFTER reported_user_id");
    echo "Added reports.conversation_id\n";
} catch (PDOException $e) {
    echo "reports.conversation_id: " . $e->getMessage() . "\n";
}

try {
    $db->exec("ALTER TABLE reports MODIFY COLUMN reason TEXT NOT NULL");
    echo "Changed reports.reason to TEXT\n";
} catch (PDOException $e) {
    echo "reports.reason: " . $e->getMessage() . "\n";
}

try {
    $db->exec("ALTER TABLE reports ADD INDEX idx_reports_conversation_id (conversation_id)");
    echo "Added index idx_reports_conversation_id\n";
} catch (PDOException $e) {
    echo "reports index: " . $e->getMessage() . "\n";
}

try {
    $db->exec("ALTER TABLE reports ADD CONSTRAINT fk_reports_conversation_id FOREIGN KEY (conversation_id) REFERENCES conversations(id) ON DELETE SET NULL");
    echo "Added FK fk_reports_conversation_id\n";
} catch (PDOException $e) {
    echo "reports fk: " . $e->getMessage() . "\n";
}

echo "\nDone.\n</pre>";

