<?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('inventario_prenda_distribuciones', function (Blueprint $table) {
            // Drop existing foreign key then make the column nullable and re-add foreign key
            $table->dropForeign(['bodega_id']);
            $table->unsignedBigInteger('bodega_id')->nullable()->change();
            $table->foreign('bodega_id')->references('id')->on('bodegas')->nullOnDelete();
        });
    }

    public function down(): void
    {
        Schema::table('inventario_prenda_distribuciones', function (Blueprint $table) {
            $table->dropForeign(['bodega_id']);
            $table->unsignedBigInteger('bodega_id')->nullable(false)->change();
            $table->foreign('bodega_id')->references('id')->on('bodegas')->cascadeOnDelete();
        });
    }
};