- TriggerAuditLog 모델 (casts, accessors, scopes) - TriggerAuditController (목록/상세/이력/롤백 미리보기/롤백 실행) - index: 대시보드 통계 + 필터 + 목록 + 파티션 현황 - show: old/new diff 뷰 (변경 컬럼 하이라이트) - history: 레코드별 변경 타임라인 - rollback-preview: SQL 미리보기 + 확인 후 실행 - 라우트 5개 등록, 메뉴 시더 (시스템 관리 > DB 변경 추적) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
55 lines
1.3 KiB
PHP
55 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Audit;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class TriggerAuditLog extends Model
|
|
{
|
|
protected $table = 'trigger_audit_logs';
|
|
|
|
public $timestamps = false;
|
|
|
|
protected $casts = [
|
|
'old_values' => 'array',
|
|
'new_values' => 'array',
|
|
'changed_columns' => 'array',
|
|
'created_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* changed_columns에서 NULL 값 제거
|
|
*/
|
|
public function getChangedColumnsAttribute($value): ?array
|
|
{
|
|
$decoded = is_string($value) ? json_decode($value, true) : $value;
|
|
if (! is_array($decoded)) {
|
|
return null;
|
|
}
|
|
|
|
return array_values(array_filter($decoded, fn ($v) => $v !== null));
|
|
}
|
|
|
|
/**
|
|
* session_info JSON → array
|
|
*/
|
|
public function getSessionInfoAttribute($value): ?array
|
|
{
|
|
if (! $value) {
|
|
return null;
|
|
}
|
|
|
|
return is_string($value) ? json_decode($value, true) : $value;
|
|
}
|
|
|
|
public function scopeForTable($query, string $tableName)
|
|
{
|
|
return $query->where('table_name', $tableName);
|
|
}
|
|
|
|
public function scopeForRecord($query, string $tableName, string $rowId)
|
|
{
|
|
return $query->where('table_name', $tableName)->where('row_id', $rowId);
|
|
}
|
|
}
|