<?php

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

class CreateDepartmentModulePermissionsTable extends Migration
{
    public function up()
    {
        Schema::create('department_module_permissions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('department_id')->constrained('departments')->cascadeOnDelete();
            $table->string('module_key', 80);
            $table->boolean('is_allowed')->default(false);
            $table->timestamps();

            $table->unique(['department_id', 'module_key']);
        });
    }

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