<?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::create('roles_menues', function (Blueprint $table): void {
            $table->id();
            $table->string('rol_codigo');
            $table->string('menu_codigo');

            $table->foreign('rol_codigo')
                ->references('codigo')
                ->on('roles')
                ->cascadeOnUpdate()
                ->cascadeOnDelete();
            $table->foreign('menu_codigo')
                ->references('code')
                ->on('menues')
                ->cascadeOnUpdate()
                ->cascadeOnDelete();

            $table->unique(['rol_codigo', 'menu_codigo']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('roles_menues');
    }
};
