Skip to content

Detection: Being able to set the recorded_at field when recording a detection. #510

@fe51

Description

@fe51

Motivation

Currently, the /api/v1/detections/ POST endpoint allow to create detections but the creation date (created_at) is imposed (= now)

While this may have been satisfactory for a while, detections can sometimes be cached on the engine side, meaning that when they are posted on the API, they get published almost all at the same datetime, even though each detection occured at different times.

Bonus point : As of today in the envdenv, this is not straight forward to create alerts in the past (for demonstration purpose), it will be easier once this issue is solved !

What should be done

  • Adds recorded_at field to detections table.

  • Updates endpoints of the api adding recorded_at in :

    • /api/v1/detections/ POST (in order to be able to set date as recorded_at as parameter )
    • /api/v1/detections/{detection_id} GET
    • /api/v1/detections/ GET
    • /api/v1/sequences/{sequence_id}/detections GET
  • Updates how detections are linked to sequences : Currently based on the created_at field, must be related to the recorded_at field

  • Add migration script (in migrations directory).

    • add upgrade (create created_at field if does not exists, and copy data as described below) and downgrade function (drop field) -> you can check other migration scripts !
    • Migrations rules : copy data from created_at field if recorded_at is empty, probably something like
UPDATE detections
SET recorded_at = created_at
WHERE recorded_at IS NULL;
  • do not forget to add tests ;)

Happy to discuss it :)

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions