新功能:為操作紀錄資料表新增效能索引
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 1m3s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped

This commit is contained in:
2026-01-20 09:17:18 +08:00
parent 7367577f6a
commit 23682b3ffe

View File

@@ -0,0 +1,45 @@
<?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::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
// 單欄索引:事件類型(高頻過濾條件)
$table->index('event', 'idx_event');
// 單欄索引:批次 UUID未來批次操作查詢
$table->index('batch_uuid', 'idx_batch_uuid');
// 複合索引 1時間 + 事件類型(最常見的組合查詢)
$table->index(['created_at', 'event'], 'idx_created_event');
// 複合索引 2主體類型 + 主體 ID + 時間(查詢特定資源的操作歷史)
$table->index(['subject_type', 'subject_id', 'created_at'], 'idx_subject_created');
// 複合索引 3操作者 + 時間(查詢特定使用者的操作紀錄)
$table->index(['causer_id', 'created_at'], 'idx_causer_created');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
$table->dropIndex('idx_event');
$table->dropIndex('idx_batch_uuid');
$table->dropIndex('idx_created_event');
$table->dropIndex('idx_subject_created');
$table->dropIndex('idx_causer_created');
});
}
};