feat: 创建数据库迁移文件
- 创建 activity_log 相关表(操作日志) - 创建 system_settings 表(系统设置) - 创建 terminals 相关表(终端管理) - 创建 sop_templates 相关表(SOP模板管理)
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateActivityLogTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::connection(config('activitylog.database_connection'))->create(config('activitylog.table_name'), function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('log_name')->nullable();
|
||||
$table->text('description');
|
||||
$table->nullableMorphs('subject', 'subject');
|
||||
$table->nullableMorphs('causer', 'causer');
|
||||
$table->json('properties')->nullable();
|
||||
$table->timestamps();
|
||||
$table->index('log_name');
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::connection(config('activitylog.database_connection'))->dropIfExists(config('activitylog.table_name'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?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');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?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');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?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('system_settings', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('key', 255)->unique()->comment('配置键');
|
||||
$table->json('value')->comment('配置值');
|
||||
$table->string('group', 100)->comment('配置分组');
|
||||
$table->text('description')->nullable()->comment('配置说明');
|
||||
$table->boolean('is_public')->default(false)->comment('是否公开');
|
||||
$table->timestamps();
|
||||
|
||||
// 添加索引
|
||||
$table->index('group', 'idx_group');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('system_settings');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
<?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('terminals', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->comment('终端名称');
|
||||
$table->string('code', 100)->unique()->comment('终端编码');
|
||||
$table->string('ip_address', 45)->nullable()->comment('IP地址');
|
||||
$table->unsignedBigInteger('station_id')->nullable()->comment('线站ID');
|
||||
$table->string('diagram_url', 500)->nullable()->comment('组态图URL');
|
||||
$table->json('display_config')->nullable()->comment('显示配置');
|
||||
$table->boolean('is_online')->default(false)->comment('在线状态');
|
||||
$table->timestamp('last_online_at')->nullable()->comment('最后在线时间');
|
||||
$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,39 @@
|
||||
<?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,36 @@
|
||||
<?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_prompts', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('terminal_id')->comment('终端ID');
|
||||
$table->text('prompt_template')->comment('提示词模板');
|
||||
$table->json('variables')->nullable()->comment('变量配置');
|
||||
$table->timestamps();
|
||||
|
||||
// 添加外键约束
|
||||
$table->foreign('terminal_id')
|
||||
->references('id')
|
||||
->on('terminals')
|
||||
->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('terminal_prompts');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
<?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_sync_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('terminal_id')->comment('终端ID');
|
||||
$table->enum('status', ['pending', 'syncing', 'synced', 'failed'])
|
||||
->default('pending')
|
||||
->comment('同步状态');
|
||||
$table->json('config_snapshot')->nullable()->comment('配置快照');
|
||||
$table->timestamp('synced_at')->nullable()->comment('同步时间');
|
||||
$table->text('error_message')->nullable()->comment('错误信息');
|
||||
$table->timestamps();
|
||||
|
||||
// 添加外键约束
|
||||
$table->foreign('terminal_id')
|
||||
->references('id')
|
||||
->on('terminals')
|
||||
->onDelete('cascade');
|
||||
|
||||
// 添加索引
|
||||
$table->index('status', 'idx_terminal_sync_logs_status');
|
||||
$table->index('synced_at', 'idx_terminal_sync_logs_synced_at');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('terminal_sync_logs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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('sop_templates', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->comment('模板名称');
|
||||
$table->text('description')->nullable()->comment('模板描述');
|
||||
$table->string('category', 100)->nullable()->comment('分类');
|
||||
$table->json('tags')->nullable()->comment('标签');
|
||||
$table->string('version', 50)->default('1.0.0')->comment('版本号');
|
||||
$table->enum('status', ['draft', 'published', 'archived'])->default('draft')->comment('状态');
|
||||
$table->json('applicable_departments')->nullable()->comment('适用部门');
|
||||
$table->json('applicable_positions')->nullable()->comment('适用岗位');
|
||||
$table->timestamp('published_at')->nullable()->comment('发布时间');
|
||||
$table->unsignedBigInteger('created_by')->nullable()->comment('创建人');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
// 添加索引
|
||||
$table->index('status', 'idx_sop_templates_status');
|
||||
$table->index('category', 'idx_sop_templates_category');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('sop_templates');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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('sop_steps', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('sop_template_id')->comment('模板ID');
|
||||
$table->integer('step_number')->comment('步骤序号');
|
||||
$table->string('title')->comment('步骤标题');
|
||||
$table->text('content')->nullable()->comment('步骤内容');
|
||||
$table->integer('sort_order')->default(0)->comment('排序');
|
||||
$table->boolean('is_required')->default(true)->comment('是否必需');
|
||||
$table->timestamps();
|
||||
|
||||
// 添加外键约束
|
||||
$table->foreign('sop_template_id')
|
||||
->references('id')
|
||||
->on('sop_templates')
|
||||
->onDelete('cascade');
|
||||
|
||||
// 添加索引
|
||||
$table->index(['sop_template_id', 'sort_order'], 'idx_template_sort');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('sop_steps');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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('sop_interactive_tasks', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('sop_step_id')->comment('步骤ID');
|
||||
$table->enum('task_type', ['confirm', 'input', 'select', 'photo', 'scan'])->comment('任务类型');
|
||||
$table->json('task_config')->nullable()->comment('任务配置');
|
||||
$table->json('validation_rules')->nullable()->comment('验证规则');
|
||||
$table->integer('timeout_seconds')->nullable()->comment('超时时间');
|
||||
$table->boolean('is_required')->default(true)->comment('是否必需');
|
||||
$table->timestamps();
|
||||
|
||||
// 添加外键约束
|
||||
$table->foreign('sop_step_id')
|
||||
->references('id')
|
||||
->on('sop_steps')
|
||||
->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('sop_interactive_tasks');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
<?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('sop_template_versions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('sop_template_id')->comment('模板ID');
|
||||
$table->string('version', 50)->comment('版本号');
|
||||
$table->text('change_log')->nullable()->comment('变更说明');
|
||||
$table->json('content_snapshot')->nullable()->comment('内容快照');
|
||||
$table->unsignedBigInteger('created_by')->nullable()->comment('创建人');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
|
||||
// 添加外键约束
|
||||
$table->foreign('sop_template_id')
|
||||
->references('id')
|
||||
->on('sop_templates')
|
||||
->onDelete('cascade');
|
||||
|
||||
// 添加索引
|
||||
$table->index(['sop_template_id', 'version'], 'idx_template_version');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('sop_template_versions');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user