mirror of
https://github.com/tcivie/meshtastic-metrics-exporter.git
synced 2024-12-27 14:39:57 -08:00
Fix issue with keys
This commit is contained in:
parent
39bfe3f703
commit
3a8f3c4c7d
|
@ -45,7 +45,7 @@ CREATE TABLE IF NOT EXISTS node_neighbors
|
||||||
neighbor_id VARCHAR,
|
neighbor_id VARCHAR,
|
||||||
snr FLOAT,
|
snr FLOAT,
|
||||||
FOREIGN KEY (node_id) REFERENCES client_details (node_id),
|
FOREIGN KEY (node_id) REFERENCES client_details (node_id),
|
||||||
FOREIGN KEY (neighbor_id) REFERENCES node_graph (node_id),
|
FOREIGN KEY (neighbor_id) REFERENCES client_details (node_id),
|
||||||
UNIQUE (node_id, neighbor_id)
|
UNIQUE (node_id, neighbor_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -504,11 +504,21 @@ class NeighborInfoAppProcessor(Processor):
|
||||||
|
|
||||||
for neighbor in neighbor_info.neighbors:
|
for neighbor in neighbor_info.neighbors:
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
INSERT INTO node_neighbors (node_id, neighbor_id, snr)
|
WITH upsert AS (
|
||||||
VALUES (%s, %s, %s)
|
INSERT INTO node_neighbors (node_id, neighbor_id, snr)
|
||||||
ON CONFLICT (node_id, neighbor_id)
|
VALUES (%s, %s, %s)
|
||||||
DO UPDATE SET snr = EXCLUDED.snr
|
ON CONFLICT (node_id, neighbor_id)
|
||||||
""", (client_details.node_id, str(neighbor.node_id), float(neighbor.snr)))
|
DO UPDATE SET snr = EXCLUDED.snr
|
||||||
|
RETURNING node_id, neighbor_id
|
||||||
|
)
|
||||||
|
INSERT INTO client_details (node_id)
|
||||||
|
SELECT node_id FROM upsert
|
||||||
|
WHERE NOT EXISTS (SELECT 1 FROM client_details WHERE node_id = upsert.node_id)
|
||||||
|
UNION
|
||||||
|
SELECT neighbor_id FROM upsert
|
||||||
|
WHERE NOT EXISTS (SELECT 1 FROM client_details WHERE node_id = upsert.neighbor_id)
|
||||||
|
ON CONFLICT (node_id) DO NOTHING;
|
||||||
|
""", (str(client_details.node_id), str(neighbor.node_id), float(neighbor.snr)))
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue