Skip to content

Commit

Permalink
Add NotNow tracking field to mysql backend. Closes #13.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepeterson committed Jul 5, 2021
1 parent cc53d28 commit eb04f03
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
14 changes: 11 additions & 3 deletions storage/mysql/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,24 @@ func (s *MySQLStorage) StoreCommandReport(r *mdm.Request, result *mdm.CommandRes
// TODO: store LastSeen?
return nil
}
notNowConstants := "NULL, 0"
notNowBumpTallySQL := ""
// note that due to the ON DUPLICATE KEY we don't UPDATE the
// not_now_at field. thus it will only represent the first NotNow.
if result.Status == "NotNow" {
notNowConstants = "CURRENT_TIMESTAMP, 1"
notNowBumpTallySQL = `, command_results.not_now_tally = command_results.not_now_tally + 1`
}
_, err := s.db.ExecContext(
r.Context, `
INSERT INTO command_results
(id, command_uuid, status, result)
(id, command_uuid, status, result, not_now_at, not_now_tally)
VALUES
(?, ?, ?, ?) AS new
(?, ?, ?, ?, `+notNowConstants+`) AS new
ON DUPLICATE KEY
UPDATE
status = new.status,
result = new.result;`,
result = new.result`+notNowBumpTallySQL+`;`,
r.ID,
result.CommandUUID,
result.Status,
Expand Down
2 changes: 2 additions & 0 deletions storage/mysql/schema.00004.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE command_results ADD COLUMN not_now_at TIMESTAMP NULL;
ALTER TABLE command_results ADD COLUMN not_now_tally INTEGER NOT NULL DEFAULT 0;
3 changes: 3 additions & 0 deletions storage/mysql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ CREATE TABLE command_results (
status VARCHAR(31) NOT NULL,
result TEXT NOT NULL,

not_now_at TIMESTAMP NULL,
not_now_tally INTEGER NOT NULL DEFAULT 0,

created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

Expand Down

0 comments on commit eb04f03

Please sign in to comment.