feat:DB 트리거 기반 데이터 변경 추적 시스템 구현
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>
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
require __DIR__.'/api/v1/common.php';
|
||||
require __DIR__.'/api/v1/stats.php';
|
||||
require __DIR__.'/api/v1/app.php';
|
||||
require __DIR__.'/api/v1/audit.php';
|
||||
|
||||
// 공유 링크 다운로드 (인증 불필요 - auth.apikey 그룹 밖)
|
||||
Route::get('/files/share/{token}', [FileStorageController::class, 'downloadShared'])->name('v1.files.share.download');
|
||||
|
||||
21
routes/api/v1/audit.php
Normal file
21
routes/api/v1/audit.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 트리거 감사 로그 API 라우트 (v1)
|
||||
*
|
||||
* - DB 트리거 기반 변경 추적 로그 조회
|
||||
* - 특정 레코드 변경 이력
|
||||
* - 롤백 미리보기 및 실행
|
||||
*/
|
||||
|
||||
use App\Http\Controllers\Api\V1\Audit\TriggerAuditLogController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::prefix('trigger-audit-logs')->group(function () {
|
||||
Route::get('', [TriggerAuditLogController::class, 'index'])->name('v1.trigger-audit-logs.index');
|
||||
Route::get('/stats', [TriggerAuditLogController::class, 'stats'])->name('v1.trigger-audit-logs.stats');
|
||||
Route::get('/{id}', [TriggerAuditLogController::class, 'show'])->whereNumber('id')->name('v1.trigger-audit-logs.show');
|
||||
Route::get('/{id}/rollback-preview', [TriggerAuditLogController::class, 'rollbackPreview'])->whereNumber('id')->name('v1.trigger-audit-logs.rollback-preview');
|
||||
Route::post('/{id}/rollback', [TriggerAuditLogController::class, 'rollbackExecute'])->whereNumber('id')->name('v1.trigger-audit-logs.rollback');
|
||||
Route::get('/{tableName}/{rowId}/history', [TriggerAuditLogController::class, 'recordHistory'])->name('v1.trigger-audit-logs.record-history');
|
||||
});
|
||||
@@ -133,6 +133,19 @@
|
||||
\Illuminate\Support\Facades\Log::error('❌ db:backup-check 스케줄러 실행 실패', ['time' => now()]);
|
||||
});
|
||||
|
||||
// ─── 트리거 감사 로그 파티션 관리 ───
|
||||
|
||||
// 매월 1일 새벽 04:10에 파티션 관리 (3개월 미래 추가 + 13개월 초과 삭제)
|
||||
Schedule::command('audit:partitions --add-months=3 --retention-months=13 --drop')
|
||||
->monthlyOn(1, '04:10')
|
||||
->appendOutputTo(storage_path('logs/scheduler.log'))
|
||||
->onSuccess(function () {
|
||||
\Illuminate\Support\Facades\Log::info('✅ audit:partitions 스케줄러 실행 성공', ['time' => now()]);
|
||||
})
|
||||
->onFailure(function () {
|
||||
\Illuminate\Support\Facades\Log::error('❌ audit:partitions 스케줄러 실행 실패', ['time' => now()]);
|
||||
});
|
||||
|
||||
// 매일 오전 09:00에 KPI 목표 대비 알림 체크
|
||||
Schedule::command('stat:check-kpi-alerts')
|
||||
->dailyAt('09:00')
|
||||
|
||||
Reference in New Issue
Block a user