🚧 Add imei time varying attributes
This commit is contained in:
+23
-1
@@ -83,4 +83,26 @@ COMMENT ON TABLE app_tokens IS
|
||||
COMMENT ON TABLE imei_map IS
|
||||
'Device settings (one JSONB document per IMEI), polled by the listener every 5 seconds; the API merges the current document into message payloads at read time.';
|
||||
COMMENT ON COLUMN imei_map.meta IS
|
||||
'Settings document; "device" (non-empty string) is the device name injected at ingest, other keys are merged into message payloads at read time.';
|
||||
'Settings document; "device" (non-empty string) is the device name injected at ingest, other keys are merged into message payloads at read time.';
|
||||
|
||||
-- Time-varying device attributes (e.g. calibration offsets): an
|
||||
-- append-only timeline. A new value = a new row; the value valid at time T
|
||||
-- is the row with the greatest effective_from <= T. GET /messages resolves
|
||||
-- each message's attributes against the device time (payload_time,
|
||||
-- falling back to received_at). No FK to imei_map: like mqtt_messages,
|
||||
-- attributes may exist for IMEIs without a settings row. The listener
|
||||
-- never reads this table (attributes are read-time corrections).
|
||||
CREATE TABLE IF NOT EXISTS imei_attributes (
|
||||
imei TEXT NOT NULL CHECK (imei ~ '^[0-9]{15}$'),
|
||||
key TEXT NOT NULL CHECK (key <> ''),
|
||||
value JSONB NOT NULL,
|
||||
effective_from TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
note TEXT,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (imei, key, effective_from)
|
||||
);
|
||||
|
||||
COMMENT ON TABLE imei_attributes IS
|
||||
'Time-varying device attributes (e.g. offsets) as an append-only timeline; the value valid at T is the row with the greatest effective_from <= T.';
|
||||
COMMENT ON COLUMN imei_attributes.effective_from IS
|
||||
'Time from which the value applies; backdating allowed. Resolved against the device timestamp (payload_time, received_at fallback) in GET /messages.';
|
||||
Reference in New Issue
Block a user