<?php
require_once 'includes/db.php';

$queries = [
    "CREATE INDEX idx_task_time_logs_task_id ON task_time_logs(task_id)",
    "CREATE INDEX idx_task_log_attachments_log_id ON task_log_attachments(log_id)",
    "CREATE INDEX idx_tasks_employee_id ON tasks(employee_id)",
    "CREATE INDEX idx_tasks_line_stage_id ON tasks(line_stage_id)"
];

echo "Adding indexes...\n";

foreach ($queries as $q) {
    try {
        $pdo->exec($q);
        echo "Success: $q\n";
    } catch (PDOException $e) {
        if ($e->getCode() == '42000' && (strpos($e->getMessage(), 'Duplicate key name') !== false || strpos($e->getMessage(), 'already exists') !== false)) {
            echo "Skipped (already exists): $q\n";
        } else {
            echo "Error: " . $e->getMessage() . "\n";
        }
    }
}
echo "Done.\n";
