refactor: kb & station & terminal
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
<?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('group_user', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('group_id')->constrained()->onDelete('cascade');
|
||||
$table->foreignId('user_id')->constrained()->onDelete('cascade');
|
||||
$table->timestamps();
|
||||
|
||||
// 添加唯一索引,确保同一用户不会重复加入同一分组
|
||||
$table->unique(['group_id', 'user_id']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('group_user');
|
||||
}
|
||||
};
|
||||
@@ -6,9 +6,6 @@ use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('documents', function (Blueprint $table) {
|
||||
@@ -19,21 +16,19 @@ return new class extends Migration
|
||||
$table->string('file_name');
|
||||
$table->bigInteger('file_size');
|
||||
$table->string('mime_type', 100);
|
||||
$table->enum('type', ['global', 'dedicated']);
|
||||
$table->foreignId('group_id')->nullable()->constrained()->onDelete('set null');
|
||||
$table->foreignId('uploaded_by')->constrained('users')->onDelete('cascade');
|
||||
$table->foreignId('knowledge_base_id')->constrained('knowledge_bases')->cascadeOnDelete();
|
||||
$table->foreignId('uploaded_by')->constrained('users')->cascadeOnDelete();
|
||||
$table->string('markdown_path', 500)->nullable();
|
||||
$table->enum('conversion_status', ['pending', 'processing', 'completed', 'failed'])->default('pending');
|
||||
$table->text('conversion_error')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
// 添加索引以优化查询性能
|
||||
$table->index('type');
|
||||
$table->index('group_id');
|
||||
|
||||
$table->index('knowledge_base_id');
|
||||
$table->index('uploaded_by');
|
||||
$table->index('conversion_status');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('documents');
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
<?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::table('documents', function (Blueprint $table) {
|
||||
// 添加 Markdown 文件路径字段
|
||||
$table->string('markdown_path', 500)->nullable()->after('description');
|
||||
|
||||
// 添加 Markdown 内容摘要字段(用于快速预览)
|
||||
$table->text('markdown_preview')->nullable()->after('markdown_path');
|
||||
|
||||
// 添加转换状态字段
|
||||
$table->enum('conversion_status', ['pending', 'processing', 'completed', 'failed'])
|
||||
->default('pending')
|
||||
->after('markdown_preview');
|
||||
|
||||
// 添加转换错误信息字段
|
||||
$table->text('conversion_error')->nullable()->after('conversion_status');
|
||||
|
||||
// 添加索引以优化查询性能
|
||||
$table->index('conversion_status');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('documents', function (Blueprint $table) {
|
||||
// 删除索引
|
||||
$table->dropIndex(['conversion_status']);
|
||||
|
||||
// 删除字段
|
||||
$table->dropColumn([
|
||||
'markdown_path',
|
||||
'markdown_preview',
|
||||
'conversion_status',
|
||||
'conversion_error'
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -13,8 +13,10 @@ class CreateActivityLogTable extends Migration
|
||||
$table->string('log_name')->nullable();
|
||||
$table->text('description');
|
||||
$table->nullableMorphs('subject', 'subject');
|
||||
$table->string('event')->nullable();
|
||||
$table->nullableMorphs('causer', 'causer');
|
||||
$table->json('properties')->nullable();
|
||||
$table->uuid('batch_uuid')->nullable();
|
||||
$table->timestamps();
|
||||
$table->index('log_name');
|
||||
});
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddEventColumnToActivityLogTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
|
||||
$table->string('event')->nullable()->after('subject_type');
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
|
||||
$table->dropColumn('event');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddBatchUuidColumnToActivityLogTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
|
||||
$table->uuid('batch_uuid')->nullable()->after('properties');
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
|
||||
$table->dropColumn('batch_uuid');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -6,24 +6,18 @@ use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('groups', function (Blueprint $table) {
|
||||
Schema::create('stations', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('name')->unique();
|
||||
$table->text('description')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('groups');
|
||||
Schema::dropIfExists('stations');
|
||||
}
|
||||
};
|
||||
@@ -6,9 +6,6 @@ use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('terminals', function (Blueprint $table) {
|
||||
@@ -16,27 +13,22 @@ return new class extends Migration
|
||||
$table->string('name')->comment('终端名称');
|
||||
$table->string('code', 100)->unique()->comment('终端编码');
|
||||
$table->string('ip_address', 45)->nullable()->comment('IP地址');
|
||||
$table->string('mac_address', 17)->nullable()->unique()->comment('MAC地址 (AA:BB:CC:DD:EE:FF)');
|
||||
$table->string('station_id', 50)->nullable()->comment('线站ID');
|
||||
$table->string('mac_address', 17)->nullable()->unique()->comment('MAC地址');
|
||||
$table->foreignId('station_id')->nullable()->constrained()->nullOnDelete();
|
||||
$table->string('diagram_url', 500)->nullable()->comment('组态界面地址');
|
||||
$table->string('scada_data_url', 500)->nullable()->comment('网关数据查询地址');
|
||||
$table->string('scada_tags_url', 500)->nullable()->comment('网关点位定义查询地址');
|
||||
$table->boolean('voice_wakeup_enabled')->default(false)->comment('语音唤醒是否启用');
|
||||
$table->string('voice_wakeup_word', 100)->nullable()->comment('语音唤醒词');
|
||||
$table->boolean('is_online')->default(false)->comment('在线状态');
|
||||
$table->timestamp('last_online_at')->nullable()->comment('最后在线时间');
|
||||
$table->boolean('voice_wakeup_enabled')->default(false);
|
||||
$table->string('voice_wakeup_word', 100)->nullable();
|
||||
$table->boolean('is_online')->default(false);
|
||||
$table->timestamp('last_online_at')->nullable();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
// 添加索引
|
||||
$table->index('station_id', 'idx_station');
|
||||
$table->index('is_online', 'idx_online');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('terminals');
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('station_user', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('station_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->timestamps();
|
||||
$table->unique(['station_id', 'user_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('station_user');
|
||||
}
|
||||
};
|
||||
@@ -1,39 +0,0 @@
|
||||
<?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('terminal_knowledge_bases', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('terminal_id')->comment('终端ID');
|
||||
$table->unsignedBigInteger('knowledge_base_id')->comment('知识库ID');
|
||||
$table->integer('priority')->default(0)->comment('优先级');
|
||||
$table->timestamps();
|
||||
|
||||
// 添加外键约束
|
||||
$table->foreign('terminal_id')
|
||||
->references('id')
|
||||
->on('terminals')
|
||||
->onDelete('cascade');
|
||||
|
||||
// 添加唯一索引,确保同一终端不会重复关联同一知识库
|
||||
$table->unique(['terminal_id', 'knowledge_base_id'], 'uk_terminal_kb');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('terminal_knowledge_bases');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('knowledge_base_station', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('station_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('knowledge_base_id')->constrained()->cascadeOnDelete();
|
||||
$table->timestamps();
|
||||
$table->unique(['station_id', 'knowledge_base_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('knowledge_base_station');
|
||||
}
|
||||
};
|
||||
@@ -1,109 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
// 权限名称映射(旧名称 => 新名称)
|
||||
$permissionMapping = [
|
||||
// 文档管理
|
||||
'document.viewAny' => 'document.view',
|
||||
|
||||
// 系统设置
|
||||
'system-setting.viewAny' => 'system-setting.view',
|
||||
|
||||
// 操作日志
|
||||
'activity-log.viewAny' => 'activity-log.view',
|
||||
|
||||
// 终端管理
|
||||
'terminal.viewAny' => 'terminal.view',
|
||||
|
||||
// 操作指引
|
||||
'guide.viewAny' => 'guide.view',
|
||||
|
||||
// 分组管理
|
||||
'group.viewAny' => 'group.view',
|
||||
|
||||
// 用户管理
|
||||
'user.viewAny' => 'user.view',
|
||||
|
||||
// 角色管理
|
||||
'role.viewAny' => 'role.view',
|
||||
];
|
||||
|
||||
foreach ($permissionMapping as $oldName => $newName) {
|
||||
$oldPermission = Permission::where('name', $oldName)->first();
|
||||
|
||||
if ($oldPermission) {
|
||||
// 检查新权限是否已存在
|
||||
$newPermission = Permission::where('name', $newName)->first();
|
||||
|
||||
if (!$newPermission) {
|
||||
// 如果新权限不存在,直接重命名
|
||||
$oldPermission->name = $newName;
|
||||
$oldPermission->save();
|
||||
} else {
|
||||
// 如果新权限已存在,需要合并权限关联
|
||||
// 将旧权限的所有角色关联转移到新权限
|
||||
$roles = $oldPermission->roles;
|
||||
foreach ($roles as $role) {
|
||||
if (!$role->hasPermissionTo($newName)) {
|
||||
$role->givePermissionTo($newName);
|
||||
}
|
||||
}
|
||||
|
||||
// 将旧权限的所有用户关联转移到新权限
|
||||
$users = $oldPermission->users;
|
||||
foreach ($users as $user) {
|
||||
if (!$user->hasPermissionTo($newName)) {
|
||||
$user->givePermissionTo($newName);
|
||||
}
|
||||
}
|
||||
|
||||
// 删除旧权限
|
||||
$oldPermission->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 删除不再需要的详情查看权限
|
||||
$detailPermissions = [
|
||||
'document.view',
|
||||
'system-setting.view',
|
||||
'activity-log.view',
|
||||
'terminal.view',
|
||||
'guide.view',
|
||||
'group.view',
|
||||
'user.view',
|
||||
'role.view',
|
||||
];
|
||||
|
||||
foreach ($detailPermissions as $permName) {
|
||||
// 只删除描述为"查看xxx详情"的权限(如果存在重复)
|
||||
$permissions = Permission::where('name', $permName)->get();
|
||||
if ($permissions->count() > 1) {
|
||||
// 保留第一个,删除其他
|
||||
$permissions->skip(1)->each(function ($permission) {
|
||||
$permission->delete();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 清除权限缓存
|
||||
app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
// 不支持回滚,因为权限合并后无法准确还原
|
||||
}
|
||||
};
|
||||
@@ -40,20 +40,19 @@ return new class extends Migration
|
||||
$table->index(['guide_id', 'sort_order']);
|
||||
});
|
||||
|
||||
Schema::create('terminal_guides', function (Blueprint $table) {
|
||||
Schema::create('guide_station', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('terminal_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('station_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('guide_id')->constrained()->cascadeOnDelete();
|
||||
$table->integer('priority')->default(0);
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['terminal_id', 'guide_id'], 'uk_terminal_guide');
|
||||
$table->unique(['station_id', 'guide_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('terminal_guides');
|
||||
Schema::dropIfExists('guide_station');
|
||||
Schema::dropIfExists('guide_pages');
|
||||
Schema::dropIfExists('guides');
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('documents', function (Blueprint $table) {
|
||||
$table->foreignId('knowledge_base_id')
|
||||
->nullable()
|
||||
->after('group_id')
|
||||
->constrained('knowledge_bases')
|
||||
->nullOnDelete();
|
||||
|
||||
$table->index('knowledge_base_id');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('documents', function (Blueprint $table) {
|
||||
$table->dropForeign(['knowledge_base_id']);
|
||||
$table->dropColumn('knowledge_base_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user