From 2640dd22bbcc20bd3c3dd982614b645c2bab6d52 Mon Sep 17 00:00:00 2001 From: Jordan Olshevski Date: Thu, 18 Apr 2024 18:53:48 -0500 Subject: [PATCH] Add timestamp with local system time during scrape --- reporting/controller.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/reporting/controller.go b/reporting/controller.go index edb0d0f..6f55936 100644 --- a/reporting/controller.go +++ b/reporting/controller.go @@ -25,6 +25,8 @@ CREATE TABLE IF NOT EXISTS swipes ( name text not null ); +ALTER TABLE swipes ADD COLUMN IF NOT EXISTS seenAt timestamp; + CREATE INDEX IF NOT EXISTS idx_swipes_cardID ON swipes (cardID); CREATE INDEX IF NOT EXISTS idx_swipes_time ON swipes (time); ` @@ -101,7 +103,7 @@ func (c *Controller) scrape(ctx context.Context) error { name = swipe.Name // fall back to UUID } - _, err := c.db.Exec(ctx, "INSERT INTO swipes (id, cardID, doorID, time, name) VALUES ($1, $2, $3, $4, $5) ON CONFLICT DO NOTHING", swipe.ID, swipe.CardID, swipe.DoorID, swipe.Time, name) + _, err := c.db.Exec(ctx, "INSERT INTO swipes (id, cardID, doorID, time, name, seenAt) VALUES ($1, $2, $3, $4, $5, NOW()) ON CONFLICT DO NOTHING", swipe.ID, swipe.CardID, swipe.DoorID, swipe.Time, name) if err != nil { return fmt.Errorf("inserting swipe %d into database: %s", swipe.ID, err) }