<?php
try {
    $pdo = new PDO('mysql:host=127.0.0.1;dbname=projects_membershipdb;charset=utf8mb4', 'root', '', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);

    $indexes = [
        'idx_contributions_paid_month' => "CREATE INDEX idx_contributions_paid_month ON contributions(paid_month)",
        'idx_contributions_status' => "CREATE INDEX idx_contributions_status ON contributions(status)",
        'idx_contributions_payment_date' => "CREATE INDEX idx_contributions_payment_date ON contributions(payment_date)",
        'idx_contributions_user_paid' => "CREATE INDEX idx_contributions_user_paid ON contributions(user_id, paid_month, status)",
    ];

    $existing = $pdo->query("SHOW INDEX FROM contributions")->fetchAll(PDO::FETCH_COLUMN, 2);
    $existing = array_unique($existing);

    foreach ($indexes as $name => $sql) {
        if (in_array($name, $existing)) {
            echo "Index {$name} already exists\n";
        } else {
            $pdo->exec($sql);
            echo "Created index {$name}\n";
        }
    }

    echo "Migration 013 completed successfully\n";
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage() . "\n";
    exit(1);
}
