From 07727dbde6b3e2a6d827b9995e72c032a06ad3d9 Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Thu, 2 Mar 2023 15:15:00 +0200 Subject: [PATCH] [#1956] normalized _requests.method to UPPERCASE --- CHANGELOG.md | 5 +++++ apis/middlewares.go | 2 +- .../logs/1677760279_uppsercase_method.go | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 migrations/logs/1677760279_uppsercase_method.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 99844924..39b5a4b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## (WIP) v0.14.0 + +- Normalized the request logs `method` value to UPPERCASE, eg. "get" => "GET" ([#1956](https://github.com/pocketbase/pocketbase/discussions/1956)). + + ## v0.13.0 - Added new "View" collection type allowing you to create a read-only collection from a custom SQL `SELECT` statement. It supports: diff --git a/apis/middlewares.go b/apis/middlewares.go index b0561dca..a1c0a51d 100644 --- a/apis/middlewares.go +++ b/apis/middlewares.go @@ -321,7 +321,7 @@ func ActivityLogger(app core.App) echo.MiddlewareFunc { model := &models.Request{ Url: httpRequest.URL.RequestURI(), - Method: strings.ToLower(httpRequest.Method), + Method: strings.ToUpper(httpRequest.Method), Status: status, Auth: requestAuth, UserIp: realUserIp(httpRequest, ip), diff --git a/migrations/logs/1677760279_uppsercase_method.go b/migrations/logs/1677760279_uppsercase_method.go new file mode 100644 index 00000000..459b4bff --- /dev/null +++ b/migrations/logs/1677760279_uppsercase_method.go @@ -0,0 +1,18 @@ +package logs + +import ( + "github.com/pocketbase/dbx" +) + +// This migrations converts all logs "method" valus to all UPPERCASE (eg. "get" => "GET"). +func init() { + LogsMigrations.Register(func(db dbx.Builder) error { + _, err := db.NewQuery("UPDATE {{_requests}} SET method=UPPER(method)").Execute() + + return err + }, func(db dbx.Builder) error { + _, err := db.NewQuery("UPDATE {{_requests}} SET method=LOWER(method)").Execute() + + return err + }) +}