<?php
require_once __DIR__ . '/../includes/functions.php';
startSecureSession();

$db = getDB();

$queries = [
    "ALTER TABLE `orders` ADD INDEX `idx_orders_user_id` (`user_id`);",
    "ALTER TABLE `orders` ADD INDEX `idx_orders_status` (`status`);",
    "ALTER TABLE `orders` ADD INDEX `idx_orders_created_at_timestamp` (`created_at_timestamp`);",
    "ALTER TABLE `payment_links` ADD INDEX `idx_pl_user_id` (`user_id`);",
    "ALTER TABLE `payment_links` ADD INDEX `idx_pl_status` (`status`);",
    "ALTER TABLE `payment_links` ADD INDEX `idx_pl_expires_at` (`expires_at`);"
];

$results = [];
foreach ($queries as $q) {
    try {
        $db->exec($q);
        $results[] = "Success: $q";
    } catch (Exception $e) {
        $results[] = "Failed (or already exists): $q - " . $e->getMessage();
    }
}

echo "<pre>";
print_r($results);
echo "</pre>";
