diff --git a/backend/migrations/2026_03_17_100000_create_api_request_logs_table.php b/backend/migrations/2026_03_17_100000_create_api_request_logs_table.php new file mode 100644 index 0000000..8686a3b --- /dev/null +++ b/backend/migrations/2026_03_17_100000_create_api_request_logs_table.php @@ -0,0 +1,41 @@ +id()->comment('主键'); + $table->unsignedBigInteger('user_id')->nullable()->comment('请求用户 ID'); + $table->string('method', 10)->comment('HTTP 方法'); + $table->string('path', 500)->comment('请求路径'); + $table->smallInteger('status_code')->comment('HTTP 状态码'); + $table->string('ip', 45)->nullable()->comment('客户端 IP'); + $table->string('user_agent', 500)->nullable()->comment('User-Agent'); + $table->jsonb('request_body')->nullable()->comment('请求体(脱敏后)'); + $table->integer('response_code')->nullable()->comment('业务响应码'); + $table->integer('duration_ms')->comment('请求耗时(毫秒)'); + $table->timestampTz('created_at')->useCurrent()->comment('创建时间'); + + $table->index('user_id'); + $table->index('path'); + $table->index('created_at'); + $table->index('status_code'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('api_request_logs'); + } +};