<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    public function up(): void
    {
        // Trigram indexes are PostgreSQL-only; skip on other drivers (e.g. sqlite in tests).
        if (DB::getDriverName() !== 'pgsql') {
            return;
        }

        DB::statement('CREATE EXTENSION IF NOT EXISTS pg_trgm');
        DB::statement('CREATE INDEX IF NOT EXISTS staff_name_trgm ON staff USING gin (name gin_trgm_ops)');
        DB::statement('CREATE INDEX IF NOT EXISTS staff_passport_trgm ON staff USING gin (passport_no gin_trgm_ops)');
    }

    public function down(): void
    {
        if (DB::getDriverName() !== 'pgsql') {
            return;
        }

        DB::statement('DROP INDEX IF EXISTS staff_name_trgm');
        DB::statement('DROP INDEX IF EXISTS staff_passport_trgm');
    }
};
