<?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('routes', function (Blueprint $table) {
            $table->id()->comment('主键');
            $table->unsignedBigInteger('group_id')->nullable()->comment('所属分组');
            $table->string('method', 10)->comment('HTTP 方法');
            $table->string('path', 255)->comment('路由路径');
            $table->string('name', 100)->nullable()->comment('路由名称');
            $table->string('label', 200)->nullable()->comment('显示名称');

            $table->unique(['method', 'path']);
            $table->foreign('group_id')->references('id')->on('route_groups')->onDelete('set null');
        });
    }

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