<?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('incoming_operation_items', function (Blueprint $table) {
            $table->unsignedBigInteger('site_transfer_allocation_id')->nullable()->after('outgoing_fulfillment_id');

            $table->foreign('site_transfer_allocation_id', 'ioi_site_transfer_alloc_fk')
                ->references('id')
                ->on('material_site_transfer_item_allocations')
                ->onDelete('set null');

            $table->index('site_transfer_allocation_id', 'ioi_site_transfer_alloc_idx');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('incoming_operation_items', function (Blueprint $table) {
            $table->dropForeign('ioi_site_transfer_alloc_fk');
            $table->dropIndex('ioi_site_transfer_alloc_idx');
            $table->dropColumn('site_transfer_allocation_id');
        });
    }
};
