<?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('wo_parts', function (Blueprint $t) {
            $t->foreignId('part_id')->nullable()->after('work_order_id')->constrained('parts')->nullOnDelete();
            $t->index(['company_id', 'part_id']);
        });
    }

    public function down(): void
    {
        Schema::table('wo_parts', function (Blueprint $t) {
            $t->dropConstrainedForeignId('part_id');
        });
    }
};
