初始化项目
This commit is contained in:
121
database/migrations/2024_01_01_000000_create_auth_tables.php
Normal file
121
database/migrations/2024_01_01_000000_create_auth_tables.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
// 管理员表
|
||||
Schema::create('auth_users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('username', 50)->unique()->comment('用户名');
|
||||
$table->string('password')->comment('密码');
|
||||
$table->string('real_name', 50)->comment('真实姓名');
|
||||
$table->string('email', 100)->nullable()->comment('邮箱');
|
||||
$table->string('phone', 20)->nullable()->comment('手机号');
|
||||
$table->unsignedBigInteger('department_id')->nullable()->comment('部门ID');
|
||||
$table->string('avatar')->nullable()->comment('头像');
|
||||
$table->tinyInteger('status')->default(1)->comment('状态:1启用 0禁用');
|
||||
$table->timestamp('last_login_at')->nullable()->comment('最后登录时间');
|
||||
$table->string('last_login_ip', 50)->nullable()->comment('最后登录IP');
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('department_id');
|
||||
$table->index('status');
|
||||
});
|
||||
|
||||
// 部门表
|
||||
Schema::create('auth_departments', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name', 100)->comment('部门名称');
|
||||
$table->unsignedBigInteger('parent_id')->default(0)->comment('父部门ID');
|
||||
$table->string('leader', 50)->nullable()->comment('部门负责人');
|
||||
$table->string('phone', 20)->nullable()->comment('联系电话');
|
||||
$table->integer('sort')->default(0)->comment('排序');
|
||||
$table->tinyInteger('status')->default(1)->comment('状态:1启用 0禁用');
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('parent_id');
|
||||
$table->index('status');
|
||||
});
|
||||
|
||||
// 角色表
|
||||
Schema::create('auth_roles', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name', 50)->unique()->comment('角色名称');
|
||||
$table->string('code', 50)->unique()->comment('角色编码');
|
||||
$table->text('description')->nullable()->comment('角色描述');
|
||||
$table->integer('sort')->default(0)->comment('排序');
|
||||
$table->tinyInteger('status')->default(1)->comment('状态:1启用 0禁用');
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('status');
|
||||
});
|
||||
|
||||
// 权限表
|
||||
Schema::create('auth_permissions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name', 100)->unique()->comment('权限名称');
|
||||
$table->string('code', 100)->unique()->comment('权限编码');
|
||||
$table->string('type', 20)->default('api')->comment('类型:api 菜单 按钮');
|
||||
$table->unsignedBigInteger('parent_id')->default(0)->comment('父级ID');
|
||||
$table->string('route')->nullable()->comment('路由');
|
||||
$table->string('component')->nullable()->comment('前端组件路径');
|
||||
$table->json('meta')->nullable()->comment('元数据(隐藏菜单、面包屑等)');
|
||||
$table->integer('sort')->default(0)->comment('排序');
|
||||
$table->tinyInteger('status')->default(1)->comment('状态:1启用 0禁用');
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('parent_id');
|
||||
$table->index('type');
|
||||
$table->index('status');
|
||||
});
|
||||
|
||||
// 用户角色关联表
|
||||
Schema::create('auth_user_role', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('user_id')->comment('用户ID');
|
||||
$table->unsignedBigInteger('role_id')->comment('角色ID');
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['user_id', 'role_id']);
|
||||
$table->index('user_id');
|
||||
$table->index('role_id');
|
||||
});
|
||||
|
||||
// 角色权限关联表
|
||||
Schema::create('auth_role_permission', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('role_id')->comment('角色ID');
|
||||
$table->unsignedBigInteger('permission_id')->comment('权限ID');
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['role_id', 'permission_id']);
|
||||
$table->index('role_id');
|
||||
$table->index('permission_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('auth_role_permission');
|
||||
Schema::dropIfExists('auth_user_role');
|
||||
Schema::dropIfExists('auth_permissions');
|
||||
Schema::dropIfExists('auth_roles');
|
||||
Schema::dropIfExists('auth_departments');
|
||||
Schema::dropIfExists('auth_users');
|
||||
}
|
||||
};
|
||||
145
database/migrations/2024_01_02_000001_create_system_tables.php
Normal file
145
database/migrations/2024_01_02_000001_create_system_tables.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
// 系统配置表
|
||||
Schema::create('system_configs', function (Blueprint $table) {
|
||||
$table->comment('系统配置表');
|
||||
$table->id();
|
||||
$table->string('group')->comment('配置分组');
|
||||
$table->string('key')->unique()->comment('配置键');
|
||||
$table->string('name')->comment('配置名称');
|
||||
$table->string('type')->default('string')->comment('字段类型:string, text, number, boolean, select, radio, checkbox, file, json');
|
||||
$table->text('options')->nullable()->comment('选项配置(JSON格式)');
|
||||
$table->text('value')->nullable()->comment('配置值');
|
||||
$table->string('default_value')->nullable()->comment('默认值');
|
||||
$table->text('description')->nullable()->comment('配置说明');
|
||||
$table->string('validation')->nullable()->comment('验证规则');
|
||||
$table->integer('sort')->default(0)->comment('排序');
|
||||
$table->boolean('is_system')->default(false)->comment('是否系统配置');
|
||||
$table->boolean('status')->default(true)->comment('状态');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->index('group');
|
||||
$table->index('key');
|
||||
});
|
||||
|
||||
// 系统日志表
|
||||
Schema::create('system_logs', function (Blueprint $table) {
|
||||
$table->comment('系统日志表');
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('user_id')->nullable()->comment('用户ID');
|
||||
$table->string('username')->nullable()->comment('用户名');
|
||||
$table->string('module')->comment('模块名称');
|
||||
$table->string('action')->comment('操作类型');
|
||||
$table->string('method')->comment('请求方法');
|
||||
$table->string('url')->comment('请求URL');
|
||||
$table->string('ip')->nullable()->comment('IP地址');
|
||||
$table->text('user_agent')->nullable()->comment('用户代理');
|
||||
$table->json('params')->nullable()->comment('请求参数');
|
||||
$table->text('result')->nullable()->comment('操作结果');
|
||||
$table->integer('status_code')->default(200)->comment('状态码');
|
||||
$table->string('status')->default('success')->comment('状态');
|
||||
$table->text('error_message')->nullable()->comment('错误信息');
|
||||
$table->integer('execution_time')->nullable()->comment('执行时间(毫秒)');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('user_id');
|
||||
$table->index('module');
|
||||
$table->index('action');
|
||||
$table->index('created_at');
|
||||
});
|
||||
|
||||
// 系统字典表
|
||||
Schema::create('system_dictionaries', function (Blueprint $table) {
|
||||
$table->comment('系统字典表');
|
||||
$table->id();
|
||||
$table->string('name')->comment('字典名称');
|
||||
$table->string('code')->unique()->comment('字典编码');
|
||||
$table->text('description')->nullable()->comment('字典描述');
|
||||
$table->boolean('status')->default(true)->comment('状态');
|
||||
$table->integer('sort')->default(0)->comment('排序');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
|
||||
// 系统字典项表
|
||||
Schema::create('system_dictionary_items', function (Blueprint $table) {
|
||||
$table->comment('系统字典项表');
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('dictionary_id')->comment('字典ID');
|
||||
$table->string('label')->comment('标签名称');
|
||||
$table->string('value')->comment('标签值');
|
||||
$table->string('color')->nullable()->comment('颜色标识');
|
||||
$table->text('description')->nullable()->comment('描述');
|
||||
$table->boolean('is_default')->default(false)->comment('是否默认');
|
||||
$table->boolean('status')->default(true)->comment('状态');
|
||||
$table->integer('sort')->default(0)->comment('排序');
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('dictionary_id')->references('id')->on('system_dictionaries')->onDelete('cascade');
|
||||
$table->index('dictionary_id');
|
||||
});
|
||||
|
||||
// 系统任务表
|
||||
Schema::create('system_tasks', function (Blueprint $table) {
|
||||
$table->comment('系统任务表');
|
||||
$table->id();
|
||||
$table->string('name')->comment('任务名称');
|
||||
$table->string('command')->comment('任务命令');
|
||||
$table->string('description')->nullable()->comment('任务描述');
|
||||
$table->string('type')->default('command')->comment('任务类型:command, job, closure');
|
||||
$table->string('expression')->comment('Cron表达式');
|
||||
$table->string('timezone')->default('Asia/Shanghai')->comment('时区');
|
||||
$table->boolean('is_active')->default(true)->comment('是否启用');
|
||||
$table->boolean('run_in_background')->default(true)->comment('是否后台运行');
|
||||
$table->boolean('without_overlapping')->default(false)->comment('是否防止重叠');
|
||||
$table->boolean('only_one')->default(false)->comment('是否只运行一个实例');
|
||||
$table->timestamp('last_run_at')->nullable()->comment('最后运行时间');
|
||||
$table->timestamp('next_run_at')->nullable()->comment('下次运行时间');
|
||||
$table->text('last_output')->nullable()->comment('最后输出');
|
||||
$table->integer('run_count')->default(0)->comment('运行次数');
|
||||
$table->integer('failed_count')->default(0)->comment('失败次数');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->index('is_active');
|
||||
});
|
||||
|
||||
// 系统城市表
|
||||
Schema::create('system_cities', function (Blueprint $table) {
|
||||
$table->comment('系统城市表');
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('parent_id')->default(0)->comment('父级ID');
|
||||
$table->string('name')->comment('城市名称');
|
||||
$table->string('code')->unique()->comment('城市编码');
|
||||
$table->string('pinyin')->nullable()->comment('拼音');
|
||||
$table->string('pinyin_short')->nullable()->comment('拼音首字母');
|
||||
$table->integer('level')->default(1)->comment('级别:1=省,2=市,3=区/县');
|
||||
$table->integer('sort')->default(0)->comment('排序');
|
||||
$table->boolean('status')->default(true)->comment('状态');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('parent_id');
|
||||
$table->index('code');
|
||||
$table->index('level');
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('system_dictionary_items');
|
||||
Schema::dropIfExists('system_dictionaries');
|
||||
Schema::dropIfExists('system_configs');
|
||||
Schema::dropIfExists('system_logs');
|
||||
Schema::dropIfExists('system_tasks');
|
||||
Schema::dropIfExists('system_cities');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user