diff --git a/database/migrations/2026_03_02_014442_create_activity_log_table.php b/database/migrations/2026_03_02_014442_create_activity_log_table.php new file mode 100644 index 0000000..7c05bc8 --- /dev/null +++ b/database/migrations/2026_03_02_014442_create_activity_log_table.php @@ -0,0 +1,27 @@ +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')); + } +} diff --git a/database/migrations/2026_03_02_014443_add_event_column_to_activity_log_table.php b/database/migrations/2026_03_02_014443_add_event_column_to_activity_log_table.php new file mode 100644 index 0000000..7b797fd --- /dev/null +++ b/database/migrations/2026_03_02_014443_add_event_column_to_activity_log_table.php @@ -0,0 +1,22 @@ +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'); + }); + } +} diff --git a/database/migrations/2026_03_02_014444_add_batch_uuid_column_to_activity_log_table.php b/database/migrations/2026_03_02_014444_add_batch_uuid_column_to_activity_log_table.php new file mode 100644 index 0000000..8f7db66 --- /dev/null +++ b/database/migrations/2026_03_02_014444_add_batch_uuid_column_to_activity_log_table.php @@ -0,0 +1,22 @@ +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'); + }); + } +} diff --git a/database/migrations/2026_03_02_014622_create_system_settings_table.php b/database/migrations/2026_03_02_014622_create_system_settings_table.php new file mode 100644 index 0000000..1f6cb55 --- /dev/null +++ b/database/migrations/2026_03_02_014622_create_system_settings_table.php @@ -0,0 +1,35 @@ +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'); + } +}; diff --git a/database/migrations/2026_03_02_014623_create_terminals_table.php b/database/migrations/2026_03_02_014623_create_terminals_table.php new file mode 100644 index 0000000..378824d --- /dev/null +++ b/database/migrations/2026_03_02_014623_create_terminals_table.php @@ -0,0 +1,40 @@ +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'); + } +}; diff --git a/database/migrations/2026_03_02_015103_create_terminal_knowledge_bases_table.php b/database/migrations/2026_03_02_015103_create_terminal_knowledge_bases_table.php new file mode 100644 index 0000000..6eff3b5 --- /dev/null +++ b/database/migrations/2026_03_02_015103_create_terminal_knowledge_bases_table.php @@ -0,0 +1,39 @@ +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'); + } +}; diff --git a/database/migrations/2026_03_02_015104_create_terminal_prompts_table.php b/database/migrations/2026_03_02_015104_create_terminal_prompts_table.php new file mode 100644 index 0000000..0b2aa1c --- /dev/null +++ b/database/migrations/2026_03_02_015104_create_terminal_prompts_table.php @@ -0,0 +1,36 @@ +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'); + } +}; diff --git a/database/migrations/2026_03_02_015105_create_terminal_sync_logs_table.php b/database/migrations/2026_03_02_015105_create_terminal_sync_logs_table.php new file mode 100644 index 0000000..b9b0cbe --- /dev/null +++ b/database/migrations/2026_03_02_015105_create_terminal_sync_logs_table.php @@ -0,0 +1,44 @@ +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'); + } +}; diff --git a/database/migrations/2026_03_02_015106_create_sop_templates_table.php b/database/migrations/2026_03_02_015106_create_sop_templates_table.php new file mode 100644 index 0000000..8af29ed --- /dev/null +++ b/database/migrations/2026_03_02_015106_create_sop_templates_table.php @@ -0,0 +1,42 @@ +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'); + } +}; diff --git a/database/migrations/2026_03_02_015107_create_sop_steps_table.php b/database/migrations/2026_03_02_015107_create_sop_steps_table.php new file mode 100644 index 0000000..4967e77 --- /dev/null +++ b/database/migrations/2026_03_02_015107_create_sop_steps_table.php @@ -0,0 +1,42 @@ +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'); + } +}; diff --git a/database/migrations/2026_03_02_015108_create_sop_interactive_tasks_table.php b/database/migrations/2026_03_02_015108_create_sop_interactive_tasks_table.php new file mode 100644 index 0000000..6b7caf5 --- /dev/null +++ b/database/migrations/2026_03_02_015108_create_sop_interactive_tasks_table.php @@ -0,0 +1,39 @@ +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'); + } +}; diff --git a/database/migrations/2026_03_02_015109_create_sop_template_versions_table.php b/database/migrations/2026_03_02_015109_create_sop_template_versions_table.php new file mode 100644 index 0000000..822c98d --- /dev/null +++ b/database/migrations/2026_03_02_015109_create_sop_template_versions_table.php @@ -0,0 +1,41 @@ +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'); + } +};