From 0421d9ef4013b80e78d9ca677bbafdea15e2f333 Mon Sep 17 00:00:00 2001 From: d3m0k1d Date: Tue, 13 Jan 2026 18:22:15 +0300 Subject: [PATCH] Fix: fix db migrations and add new row viewed --- internal/parser/NginxParser.go | 1 - internal/storage/migrations.go | 1 + internal/storage/models.go | 20 ++++++++++++-------- internal/storage/writer.go | 8 +------- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/internal/parser/NginxParser.go b/internal/parser/NginxParser.go index 5b5b2d4..62a90b9 100644 --- a/internal/parser/NginxParser.go +++ b/internal/parser/NginxParser.go @@ -40,7 +40,6 @@ func (p *NginxParser) Parse(eventCh <-chan Event, resultCh chan<- *storage.LogEn Path: &path, Status: &status, Method: &method, - Reason: nil, } } }() diff --git a/internal/storage/migrations.go b/internal/storage/migrations.go index 5375f8d..a96d3ba 100644 --- a/internal/storage/migrations.go +++ b/internal/storage/migrations.go @@ -9,6 +9,7 @@ CREATE TABLE IF NOT EXISTS requests ( path TEXT, method TEXT, status TEXT, + viewed BOOLEAN DEFAULT FALSE, created_at DATETIME DEFAULT CURRENT_TIMESTAMP ); diff --git a/internal/storage/models.go b/internal/storage/models.go index 98d4c62..a1730fe 100644 --- a/internal/storage/models.go +++ b/internal/storage/models.go @@ -1,15 +1,19 @@ package storage type LogEntry struct { - Service string - IP string - Path *string - Status *string - Method *string - Reason *string + ID int `db:"id"` + Service string `db:"service"` + IP string `db:"ip"` + Path *string `db:"path"` + Status *string `db:"status"` + Method *string `db:"method"` + IsViewed *bool `db:"viewed"` + CreatedAt string `db:"created_at"` } type Ban struct { - IP string - Reason *string + ID int `db:"id"` + IP string `db:"ip"` + Reason *string `db:"reason"` + BannedAt string `db:"banned_at"` } diff --git a/internal/storage/writer.go b/internal/storage/writer.go index 87a958d..a1110eb 100644 --- a/internal/storage/writer.go +++ b/internal/storage/writer.go @@ -21,19 +21,13 @@ func Write(db *DB, resultCh <-chan *LogEntry) { method = *result.Method } - reason := "" - if result.Reason != nil { - reason = *result.Reason - } - _, err := db.db.Exec( - "INSERT INTO requests (service, ip, path, method, status, reason, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)", + "INSERT INTO requests (service, ip, path, method, status, created_at) VALUES (?, ?, ?, ?, ?, ?)", result.Service, result.IP, path, method, status, - reason, time.Now().Format(time.RFC3339), ) if err != nil {