feat: 통합 감사 로그 도입 및 조회 API/스케줄러 추가

- DB: 감사 로그 테이블(audit_logs) 마이그레이션 및 인덱스 추가
- Config: audit.php 추가(AUDIT_RETENTION_DAYS, AUDIT_LOG_READS 토글)
- Model/Service: AuditLog 모델, AuditLogger 서비스 생성
- 도메인 훅: ModelVersion.release(released), BomTemplate upsert/update/delete/replaceItems/clone 기록, diff 조회는 설정 기반 기록
- API: GET /api/v1/design/audit-logs 추가(FormRequest/Service/Controller, 필터 page/size/target_type/target_id/action/actor_id/from/to/sort/order)
- Swagger: 감사 로그 조회 문서 추가(Design Audit 태그)
- Console: audit:prune 커맨드 추가 및 스케줄러 매일 03:10 실행 등록(시스템 크론 schedule:run 필요)
- Fix: PruneAuditLogs import 충돌 제거(Google ServiceControl AuditLog 제거)
This commit is contained in:
2025-09-11 14:39:55 +09:00
parent 17fa82c35b
commit 785e367472
13 changed files with 404 additions and 1 deletions

View File

@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::create('audit_logs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('tenant_id')->comment('테넌트ID');
$table->string('target_type', 100)->comment('리소스 타입 예: model_version, bom_template');
$table->unsignedBigInteger('target_id')->nullable()->comment('리소스 ID');
$table->string('action', 50)->comment('액션: created/updated/deleted/released/cloned/items_replaced/diff_viewed');
$table->json('before')->nullable()->comment('변경 전 스냅샷');
$table->json('after')->nullable()->comment('변경 후 스냅샷');
$table->unsignedBigInteger('actor_id')->nullable()->comment('사용자ID(옵션)');
$table->string('ip', 45)->nullable()->comment('요청 IP');
$table->string('ua', 255)->nullable()->comment('User-Agent');
$table->timestamp('created_at')->useCurrent();
$table->index(['tenant_id', 'target_type', 'target_id', 'created_at'], 'ix_audit_tenant_target_created');
$table->index(['tenant_id', 'actor_id', 'created_at'], 'ix_audit_tenant_actor_created');
});
}
public function down(): void
{
Schema::dropIfExists('audit_logs');
}
};