add routes and route_group table
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use Hyperf\Database\Model\Relations\BelongsTo;
|
||||
use Hyperf\Database\Model\Relations\HasMany;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int|null $group_id
|
||||
* @property string $method
|
||||
* @property string $path
|
||||
* @property string|null $name
|
||||
* @property string|null $label
|
||||
*/
|
||||
class Route extends Model
|
||||
{
|
||||
protected ?string $table = 'routes';
|
||||
|
||||
public bool $timestamps = false;
|
||||
|
||||
protected array $fillable = [
|
||||
'group_id',
|
||||
'method',
|
||||
'path',
|
||||
'name',
|
||||
'label',
|
||||
];
|
||||
|
||||
protected array $casts = [
|
||||
'id' => 'integer',
|
||||
'group_id' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* 所属分组
|
||||
*/
|
||||
public function group(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(RouteGroup::class, 'group_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 路由的角色覆盖规则
|
||||
*/
|
||||
public function overrides(): HasMany
|
||||
{
|
||||
return $this->hasMany(RoleRouteOverride::class, 'route_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?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('route_groups', function (Blueprint $table) {
|
||||
$table->id()->comment('主键');
|
||||
$table->string('name', 50)->unique()->comment('分组标识');
|
||||
$table->string('label', 100)->comment('显示名称');
|
||||
$table->text('description')->nullable()->comment('描述');
|
||||
$table->integer('sort_order')->default(0)->comment('排序');
|
||||
$table->timestampTz('created_at')->useCurrent()->comment('创建时间');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('route_groups');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
<?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');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
<?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_groups', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('role_id')->comment('角色 ID');
|
||||
$table->unsignedBigInteger('group_id')->comment('路由分组 ID');
|
||||
|
||||
$table->primary(['role_id', 'group_id']);
|
||||
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
|
||||
$table->foreign('group_id')->references('id')->on('route_groups')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('role_route_groups');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user