<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('import_mappings', function (Blueprint $table) {
            if (! Schema::hasColumn('import_mappings', 'position')) {
                $table->unsignedInteger('position')->nullable()->after('options');
            }
            $table->index(['import_id', 'position']);
        });
    }

    public function down(): void
    {
        Schema::table('import_mappings', function (Blueprint $table) {
            if (Schema::hasColumn('import_mappings', 'position')) {
                $table->dropIndex(['import_id', 'position']);
                $table->dropColumn('position');
            }
        });
    }
};
