From 1386ed78c458eb6debd47a83afee7df432fff50f Mon Sep 17 00:00:00 2001 From: liamcottle Date: Tue, 16 Apr 2024 14:15:25 +1200 Subject: [PATCH] add migration to add columns and drop existing traceroutes, also updated ui --- .../migration.sql | 27 +++++++++++++++++++ prisma/schema.prisma | 14 +++++----- src/index.js | 2 +- src/mqtt.js | 6 +++-- src/public/index.html | 24 ++++++++--------- 5 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 prisma/migrations/20240416014304_add_new_traceroute_columns_and_remove_node_id_column/migration.sql diff --git a/prisma/migrations/20240416014304_add_new_traceroute_columns_and_remove_node_id_column/migration.sql b/prisma/migrations/20240416014304_add_new_traceroute_columns_and_remove_node_id_column/migration.sql new file mode 100644 index 0000000..4f71d48 --- /dev/null +++ b/prisma/migrations/20240416014304_add_new_traceroute_columns_and_remove_node_id_column/migration.sql @@ -0,0 +1,27 @@ +/* + Warnings: + + - You are about to drop the column `node_id` on the `traceroutes` table. All the data in the column will be lost. + - Added the required column `from` to the `traceroutes` table without a default value. This is not possible if the table is not empty. + - Added the required column `to` to the `traceroutes` table without a default value. This is not possible if the table is not empty. + - Added the required column `want_response` to the `traceroutes` table without a default value. This is not possible if the table is not empty. + +*/ + +-- NOTE: manually added query, to drop existing traceroutes before adding required columns +TRUNCATE table `traceroutes`; + +-- DropIndex +DROP INDEX `traceroutes_node_id_idx` ON `traceroutes`; + +-- AlterTable +ALTER TABLE `traceroutes` DROP COLUMN `node_id`, + ADD COLUMN `from` BIGINT NOT NULL, + ADD COLUMN `to` BIGINT NOT NULL, + ADD COLUMN `want_response` BOOLEAN NOT NULL; + +-- CreateIndex +CREATE INDEX `traceroutes_to_idx` ON `traceroutes`(`to`); + +-- CreateIndex +CREATE INDEX `traceroutes_from_idx` ON `traceroutes`(`from`); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 23d71e1..3686ae6 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -162,11 +162,11 @@ model TextMessage { } model TraceRoute { - id BigInt @id @default(autoincrement()) - from_id BigInt @default(0) - to_id BigInt @default(0) - want_response Boolean @default(true) - route Json + id BigInt @id @default(autoincrement()) + to BigInt + from BigInt + want_response Boolean + route Json channel Int? packet_id BigInt? @@ -178,8 +178,8 @@ model TraceRoute { @@index(created_at) @@index(updated_at) - @@index(from_id) - @@index(to_id) + @@index(to) + @@index(from) @@map("traceroutes") } diff --git a/src/index.js b/src/index.js index d9574e2..79ff34c 100644 --- a/src/index.js +++ b/src/index.js @@ -284,7 +284,7 @@ app.get('/api/v1/nodes/:nodeId/traceroutes', async (req, res) => { // get latest traceroutes // We want replies where want_response is false and it will be "to" the // requester. - const traceroutes = await prisma.$queryRaw`SELECT * FROM traceroutes WHERE want_response = false and to_id = ${node.node_id} and gateway_id is not null order by id desc limit ${count}`; + const traceroutes = await prisma.$queryRaw`SELECT * FROM traceroutes WHERE want_response = false and \`to\` = ${node.node_id} and gateway_id is not null order by id desc limit ${count}`; res.json({ traceroutes: traceroutes, diff --git a/src/mqtt.js b/src/mqtt.js index f2bb380..2525ee0 100644 --- a/src/mqtt.js +++ b/src/mqtt.js @@ -579,7 +579,9 @@ client.on("message", async (topic, message) => { if(logKnownPacketTypes) { console.log("TRACEROUTE_APP", { + to: envelope.packet.to.toString(16), from: envelope.packet.from.toString(16), + want_response: envelope.packet.decoded.wantResponse, route_discovery: routeDiscovery, }); } @@ -587,8 +589,8 @@ client.on("message", async (topic, message) => { try { await prisma.traceRoute.create({ data: { - from_id: envelope.packet.from, - to_id: envelope.packet.to, + to: envelope.packet.to, + from: envelope.packet.from, want_response: envelope.packet.decoded.wantResponse, route: routeDiscovery.route, channel: envelope.packet.channel, diff --git a/src/public/index.html b/src/public/index.html index 62435cb..b3919dc 100644 --- a/src/public/index.html +++ b/src/public/index.html @@ -894,8 +894,8 @@
-

{{ JSON.parse(traceroute.route).length }} hops {{ traceroute.channel_id ? `on ${traceroute.channel_id}` : '' }}

-
Gated {{ moment(new Date(traceroute.updated_at)).fromNow() }}
+

{{ findNodeById(traceroute.to)?.long_name || '???' }} to {{ findNodeById(traceroute.from)?.long_name || '???' }}

+
{{ moment(new Date(traceroute.updated_at)).fromNow() }} - {{ traceroute.route.length }} hops {{ traceroute.channel_id ? `on ${traceroute.channel_id}` : '' }}
@@ -1075,7 +1075,7 @@

Traceroute #{{ selectedTraceRoute.id }}

-

{{ moment(new Date(selectedTraceRoute.updated_at)).fromNow() }}

+

{{ moment(new Date(selectedTraceRoute.updated_at)).fromNow() }} - {{ selectedTraceRoute.route.length }} hops {{ selectedTraceRoute.channel_id ? `on ${selectedTraceRoute.channel_id}` : '' }}

-
{{ findNodeById(selectedTraceRoute.to_id)?.long_name || '???' }}
-
Hex ID: !{{ Number(selectedTraceRoute.to_id).toString(16) }}
+
{{ findNodeById(selectedTraceRoute.to)?.long_name || '???' }}
+
Hex ID: !{{ Number(selectedTraceRoute.to).toString(16) }}
Started the traceroute
-
  • +
  • @@ -1127,8 +1127,8 @@
  • - -
  • + +
  • @@ -1136,13 +1136,13 @@
    -
    {{ findNodeById(selectedTraceRoute.from_id)?.long_name || '???' }}
    -
    Hex ID: !{{ Number(selectedTraceRoute.from_id).toString(16) }}
    +
    {{ findNodeById(selectedTraceRoute.from)?.long_name || '???' }}
    +
    Hex ID: !{{ Number(selectedTraceRoute.from).toString(16) }}
    Replied to traceroute
  • - +