fix(db): add activity_log migrations to central database
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 49s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped

This commit is contained in:
2026-01-28 14:10:53 +08:00
parent 965418077b
commit 852370cfe0
4 changed files with 116 additions and 0 deletions

View File

@@ -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'));
}
}

View File

@@ -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');
});
}
}

View File

@@ -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');
});
}
}

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');
});
}
};