<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('role_route_overrides', function (Blueprint $table) {
            $table->unsignedBigInteger('role_id')->comment('角色 ID');
            $table->unsignedBigInteger('route_id')->comment('路由 ID');
            $table->boolean('allowed')->comment('true=强制允许, false=强制拒绝');

            $table->primary(['role_id', 'route_id']);
            $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
            $table->foreign('route_id')->references('id')->on('routes')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('role_route_overrides');
    }
};
