🎉 Initial commit

This commit is contained in:
Jonas Bengtsson
2026-08-31 21:13:38 +02:00
commit 26a027d1e8
26 changed files with 1544 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
-- Schema for the nodeledge MQTT data pipeline.
-- Executed automatically by the postgres image on the FIRST database start
-- (files in /docker-entrypoint-initdb.d are only run against an empty data dir).
CREATE TABLE IF NOT EXISTS mqtt_messages (
id BIGSERIAL PRIMARY KEY,
received_at TIMESTAMPTZ NOT NULL DEFAULT now(),
topic TEXT NOT NULL,
imei TEXT NOT NULL,
device TEXT NOT NULL,
payload JSONB NOT NULL,
payload_time TIMESTAMPTZ
);
-- "newest messages for a device" and "recent messages overall"
-- (received_at = server receipt time)
CREATE INDEX IF NOT EXISTS idx_mqtt_messages_imei_time
ON mqtt_messages (imei, received_at DESC);
CREATE INDEX IF NOT EXISTS idx_mqtt_messages_time
ON mqtt_messages (received_at DESC);
-- device-timestamp framing (payload_time extracted from the JSON payload;
-- NULL when the payload carries no parseable timestamp)
CREATE INDEX IF NOT EXISTS idx_mqtt_messages_imei_ptime
ON mqtt_messages (imei, payload_time DESC);
CREATE INDEX IF NOT EXISTS idx_mqtt_messages_ptime
ON mqtt_messages (payload_time DESC);
-- exact topic lookups
CREATE INDEX IF NOT EXISTS idx_mqtt_messages_topic
ON mqtt_messages (topic);
COMMENT ON COLUMN mqtt_messages.payload_time IS
'Device timestamp extracted from the JSON payload at ingest time; NULL when absent or unparseable. received_at is the server receipt time.';
COMMENT ON TABLE mqtt_messages IS
'JSON payloads received over MQTT; payload contains the original JSON with imei and device injected by the listener.';