<?php

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

return new class extends Migration
{
    /**
     * Agrega gerencia_id a la tabla users.
     */
    public function up(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->unsignedInteger('gerencia_id')->nullable()->after('departamento_id');
            $table->foreign('gerencia_id')->references('id')->on('cat_gerencias')->onDelete('set null');
        });
    }

    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropForeign(['gerencia_id']);
            $table->dropColumn('gerencia_id');
        });
    }
};
