<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Add a FULLTEXT index on artworks.title and artworks.description to
     * replace the 20+ OR LIKE conditions used in search queries.
     *
     * Usage after migration:
     *   ->whereFullText(['title', 'description'], $query)
     */
    public function up(): void
    {
        if (Schema::getConnection()->getDriverName() === 'sqlite') {
            return;
        }

        Schema::table('artworks', function (Blueprint $table) {
            $table->fullText(['title', 'description'], 'artworks_title_description_fulltext');
        });
    }

    public function down(): void
    {
        if (Schema::getConnection()->getDriverName() === 'sqlite') {
            return;
        }

        Schema::table('artworks', function (Blueprint $table) {
            $table->dropFullText('artworks_title_description_fulltext');
        });
    }
};
