Phase 1: DB 기반 구축 - trigger_audit_logs 테이블 (RANGE 파티셔닝 15개, 3개 인덱스) - 789개 MySQL AFTER 트리거 (263 테이블 × INSERT/UPDATE/DELETE) - SetAuditSessionVariables 미들웨어 (@sam_actor_id, @sam_session_info) Phase 2: 복구 메커니즘 - TriggerAuditLog 모델, TriggerAuditLogService, AuditRollbackService - 6개 API 엔드포인트 (index, show, stats, history, rollback-preview, rollback) - FormRequest 검증 (TriggerAuditLogIndexRequest, TriggerAuditRollbackRequest) Phase 3: 관리 도구 - v_unified_audit VIEW (APP + TRIGGER 통합, COLLATE 처리) - audit:partitions 커맨드 (파티션 추가/삭제, dry-run) - audit:triggers 커맨드 (트리거 재생성, 테이블별/전체) - 월 1회 파티션 자동 관리 스케줄러 등록 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
28 lines
755 B
PHP
28 lines
755 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class SetAuditSessionVariables
|
|
{
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
if (auth()->check()) {
|
|
DB::statement('SET @sam_actor_id = ?', [auth()->id()]);
|
|
DB::statement('SET @sam_session_info = ?', [
|
|
json_encode([
|
|
'ip' => $request->ip(),
|
|
'ua' => mb_substr((string) $request->userAgent(), 0, 255),
|
|
'route' => $request->route()?->getName(),
|
|
], JSON_UNESCAPED_UNICODE),
|
|
]);
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|