<?php

declare(strict_types=1);

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

return new class extends Migration
{
    /**
     * 添加 (user_id, key_hash) 联合索引，支撑新 key 格式的精确查询
     */
    public function up(): void
    {
        Schema::table('api_keys', function (Blueprint $table) {
            $table->index(['user_id', 'key_hash'], 'idx_api_keys_user_id_key_hash');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('api_keys', function (Blueprint $table) {
            $table->dropIndex('idx_api_keys_user_id_key_hash');
        });
    }
};
