Skip to content

Commit

Permalink
Add timestamp with local system time during scrape
Browse files Browse the repository at this point in the history
  • Loading branch information
jveski committed Apr 18, 2024
1 parent b26e1cb commit 2640dd2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion reporting/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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);
`
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 2640dd2

Please sign in to comment.