新功能:為操作紀錄資料表新增效能索引
This commit is contained in:
@@ -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');
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user