mirror of
https://devops.lemonos.cn/lawson/FendxPHP.git
synced 2026-06-15 23:12:49 +08:00
feat(database): 添加用户角色权限系统及相关监控功能
- 创建用户表(users)包含基本信息和认证字段 - 创建角色表(roles)用于权限控制 - 创建权限表(permissions)定义系统权限 - 创建用户角色关联表(user_roles)建立用户与角色关系 - 创建角色权限关联表(role_permissions)建立角色与权限关系 - 创建迁移记录表(migrations)追踪数据库变更 - 添加AdminController提供管理员面板功能 - 实现系统监控、配置管理、缓存清理等功能 - 添加AOP切面编程支持的各种通知类型 - 实现告警管理AlertManager支持多渠道告警 - 添加文档注解接口规范
This commit is contained in:
48
database/migrations/2024_01_15_000001_create_users_table.php
Normal file
48
database/migrations/2024_01_15_000001_create_users_table.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Fendx\Database\Schema\Schema;
|
||||
use Fendx\Database\Migration;
|
||||
|
||||
/**
|
||||
* 创建用户表
|
||||
*/
|
||||
class CreateUsersTable extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('users', function (Schema\Table $table) {
|
||||
$table->id('id')->primary()->autoIncrement();
|
||||
$table->string('username', 50)->unique()->comment('用户名');
|
||||
$table->string('email', 100)->unique()->comment('邮箱');
|
||||
$table->string('password', 255)->comment('密码');
|
||||
$table->string('nickname', 50)->nullable()->comment('昵称');
|
||||
$table->string('avatar', 255)->nullable()->comment('头像');
|
||||
$table->string('phone', 20)->nullable()->comment('手机号');
|
||||
$table->enum('gender', ['male', 'female', 'other'])->nullable()->comment('性别');
|
||||
$table->date('birthday')->nullable()->comment('生日');
|
||||
$table->text('bio')->nullable()->comment('个人简介');
|
||||
$table->string('status', 20)->default('active')->comment('状态: active, inactive, banned');
|
||||
$table->boolean('email_verified')->default(false)->comment('邮箱是否验证');
|
||||
$table->boolean('phone_verified')->default(false)->comment('手机是否验证');
|
||||
$table->timestamp('email_verified_at')->nullable()->comment('邮箱验证时间');
|
||||
$table->timestamp('phone_verified_at')->nullable()->comment('手机验证时间');
|
||||
$table->timestamp('last_login_at')->nullable()->comment('最后登录时间');
|
||||
$table->string('last_login_ip', 45)->nullable()->comment('最后登录IP');
|
||||
$table->timestamp('created_at')->useCurrent()->comment('创建时间');
|
||||
$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate()->comment('更新时间');
|
||||
|
||||
// 索引
|
||||
$table->index('username');
|
||||
$table->index('email');
|
||||
$table->index('status');
|
||||
$table->index('created_at');
|
||||
$table->index('last_login_at');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
}
|
||||
}
|
||||
37
database/migrations/2024_01_15_000002_create_roles_table.php
Normal file
37
database/migrations/2024_01_15_000002_create_roles_table.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Fendx\Database\Schema\Schema;
|
||||
use Fendx\Database\Migration;
|
||||
|
||||
/**
|
||||
* 创建角色表
|
||||
*/
|
||||
class CreateRolesTable extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('roles', function (Schema\Table $table) {
|
||||
$table->id('id')->primary()->autoIncrement();
|
||||
$table->string('name', 50)->unique()->comment('角色名称');
|
||||
$table->string('display_name', 100)->comment('显示名称');
|
||||
$table->text('description')->nullable()->comment('角色描述');
|
||||
$table->string('guard_name', 50)->default('web')->comment('守卫名称');
|
||||
$table->boolean('is_active')->default(true)->comment('是否激活');
|
||||
$table->integer('sort_order')->default(0)->comment('排序');
|
||||
$table->timestamp('created_at')->useCurrent()->comment('创建时间');
|
||||
$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate()->comment('更新时间');
|
||||
|
||||
// 索引
|
||||
$table->index('name');
|
||||
$table->index('guard_name');
|
||||
$table->index('is_active');
|
||||
$table->index('sort_order');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('roles');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Fendx\Database\Schema\Schema;
|
||||
use Fendx\Database\Migration;
|
||||
|
||||
/**
|
||||
* 创建权限表
|
||||
*/
|
||||
class CreatePermissionsTable extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('permissions', function (Schema\Table $table) {
|
||||
$table->id('id')->primary()->autoIncrement();
|
||||
$table->string('name', 100)->unique()->comment('权限名称');
|
||||
$table->string('display_name', 100)->comment('显示名称');
|
||||
$table->text('description')->nullable()->comment('权限描述');
|
||||
$table->string('guard_name', 50)->default('web')->comment('守卫名称');
|
||||
$table->string('group_name', 50)->nullable()->comment('权限分组');
|
||||
$table->boolean('is_active')->default(true)->comment('是否激活');
|
||||
$table->integer('sort_order')->default(0)->comment('排序');
|
||||
$table->timestamp('created_at')->useCurrent()->comment('创建时间');
|
||||
$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate()->comment('更新时间');
|
||||
|
||||
// 索引
|
||||
$table->index('name');
|
||||
$table->index('guard_name');
|
||||
$table->index('group_name');
|
||||
$table->index('is_active');
|
||||
$table->index('sort_order');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('permissions');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Fendx\Database\Schema\Schema;
|
||||
use Fendx\Database\Migration;
|
||||
|
||||
/**
|
||||
* 创建用户角色关联表
|
||||
*/
|
||||
class CreateUserRolesTable extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('user_roles', function (Schema\Table $table) {
|
||||
$table->id('id')->primary()->autoIncrement();
|
||||
$table->unsignedBigInteger('user_id')->comment('用户ID');
|
||||
$table->unsignedBigInteger('role_id')->comment('角色ID');
|
||||
$table->string('guard_name', 50)->default('web')->comment('守卫名称');
|
||||
$table->timestamp('created_at')->useCurrent()->comment('创建时间');
|
||||
|
||||
// 外键约束
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
|
||||
|
||||
// 唯一索引
|
||||
$table->unique(['user_id', 'role_id', 'guard_name'], 'user_roles_unique');
|
||||
|
||||
// 索引
|
||||
$table->index('user_id');
|
||||
$table->index('role_id');
|
||||
$table->index('guard_name');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('user_roles');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Fendx\Database\Schema\Schema;
|
||||
use Fendx\Database\Migration;
|
||||
|
||||
/**
|
||||
* 创建角色权限关联表
|
||||
*/
|
||||
class CreateRolePermissionsTable extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('role_permissions', function (Schema\Table $table) {
|
||||
$table->id('id')->primary()->autoIncrement();
|
||||
$table->unsignedBigInteger('role_id')->comment('角色ID');
|
||||
$table->unsignedBigInteger('permission_id')->comment('权限ID');
|
||||
$table->string('guard_name', 50)->default('web')->comment('守卫名称');
|
||||
$table->timestamp('created_at')->useCurrent()->comment('创建时间');
|
||||
|
||||
// 外键约束
|
||||
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
|
||||
$table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade');
|
||||
|
||||
// 唯一索引
|
||||
$table->unique(['role_id', 'permission_id', 'guard_name'], 'role_permissions_unique');
|
||||
|
||||
// 索引
|
||||
$table->index('role_id');
|
||||
$table->index('permission_id');
|
||||
$table->index('guard_name');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('role_permissions');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Fendx\Database\Schema\Schema;
|
||||
use Fendx\Database\Migration;
|
||||
|
||||
/**
|
||||
* 创建迁移记录表
|
||||
*/
|
||||
class CreateMigrationsTable extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('migrations', function (Schema\Table $table) {
|
||||
$table->id('id')->primary()->autoIncrement();
|
||||
$table->string('migration', 255)->comment('迁移文件名');
|
||||
$table->integer('batch')->comment('批次号');
|
||||
$table->timestamp('ran_at')->useCurrent()->comment('执行时间');
|
||||
|
||||
// 索引
|
||||
$table->index('migration');
|
||||
$table->index('batch');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('migrations');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user