<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('attachments', function (Blueprint $table) {
            $table->string('attachType')->nullable()->default('nul')->after('original_filename');
            $table->index('attachable_type', 'attachable_type');
            $table->index('attachable_id', 'attachable_id');
            $table->index(['attachable_type', 'attachable_id'], 'attachable_type_attachable_id');
            $table->index('attachType', 'attachType');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('attachments', function (Blueprint $table) {
            $table->dropIndex('attachType');
            $table->dropIndex('attachable_type');
            $table->dropIndex('attachable_id');
            $table->dropIndex('attachable_type_attachable_id');
            $table->dropColumn('attachType');
        });
    }
};
