add directory for common assets

This commit is contained in:
2025-04-15 15:51:27 -04:00
parent c0a59bd30a
commit 911983d250
68 changed files with 8 additions and 0 deletions

View File

@ -0,0 +1,17 @@
-- CreateTable
CREATE TABLE `nodes` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`node_id` BIGINT NOT NULL,
`long_name` VARCHAR(191) NOT NULL,
`short_name` VARCHAR(191) NOT NULL,
`hardware_model` INTEGER NOT NULL,
`is_licensed` BOOLEAN NOT NULL,
`role` INTEGER NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
UNIQUE INDEX `nodes_node_id_key`(`node_id`),
INDEX `nodes_created_at_idx`(`created_at`),
INDEX `nodes_updated_at_idx`(`updated_at`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

View File

@ -0,0 +1,4 @@
-- AlterTable
ALTER TABLE `nodes` ADD COLUMN `altitude` INTEGER NULL,
ADD COLUMN `latitude` INTEGER NULL,
ADD COLUMN `longitude` INTEGER NULL;

View File

@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE `nodes` ADD COLUMN `air_util_tx` DECIMAL(65, 30) NULL,
ADD COLUMN `battery_level` INTEGER NULL,
ADD COLUMN `channel_utilization` DECIMAL(65, 30) NULL,
ADD COLUMN `voltage` DECIMAL(65, 30) NULL;

View File

@ -0,0 +1,13 @@
-- CreateTable
CREATE TABLE `neighbour_infos` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`node_id` BIGINT NOT NULL,
`node_broadcast_interval_secs` INTEGER NOT NULL,
`neighbours` JSON NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
INDEX `neighbour_infos_created_at_idx`(`created_at`),
INDEX `neighbour_infos_updated_at_idx`(`updated_at`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

View File

@ -0,0 +1,13 @@
-- CreateTable
CREATE TABLE `traceroutes` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`node_id` BIGINT NOT NULL,
`route` JSON NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
INDEX `traceroutes_created_at_idx`(`created_at`),
INDEX `traceroutes_updated_at_idx`(`updated_at`),
INDEX `traceroutes_node_id_idx`(`node_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

View File

@ -0,0 +1,25 @@
-- CreateTable
CREATE TABLE `map_reports` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`node_id` BIGINT NOT NULL,
`long_name` VARCHAR(191) NOT NULL,
`short_name` VARCHAR(191) NOT NULL,
`role` INTEGER NOT NULL,
`hardware_model` INTEGER NOT NULL,
`firmware_version` VARCHAR(191) NOT NULL,
`region` INTEGER NULL,
`modem_preset` INTEGER NULL,
`has_default_channel` BOOLEAN NULL,
`latitude` INTEGER NULL,
`longitude` INTEGER NULL,
`altitude` INTEGER NULL,
`position_precision` INTEGER NULL,
`num_online_local_nodes` INTEGER NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
INDEX `map_reports_created_at_idx`(`created_at`),
INDEX `map_reports_updated_at_idx`(`updated_at`),
INDEX `map_reports_node_id_idx`(`node_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

View File

@ -0,0 +1,5 @@
-- CreateIndex
CREATE INDEX `neighbour_infos_node_id_idx` ON `neighbour_infos`(`node_id`);
-- CreateIndex
CREATE INDEX `nodes_node_id_idx` ON `nodes`(`node_id`);

View File

@ -0,0 +1,16 @@
-- CreateTable
CREATE TABLE `device_metrics` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`node_id` BIGINT NOT NULL,
`battery_level` INTEGER NULL,
`voltage` DECIMAL(65, 30) NULL,
`channel_utilization` DECIMAL(65, 30) NULL,
`air_util_tx` DECIMAL(65, 30) NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
INDEX `device_metrics_created_at_idx`(`created_at`),
INDEX `device_metrics_updated_at_idx`(`updated_at`),
INDEX `device_metrics_node_id_idx`(`node_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

View File

@ -0,0 +1,25 @@
-- CreateTable
CREATE TABLE `text_messages` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`to` BIGINT NOT NULL,
`from` BIGINT NOT NULL,
`channel` INTEGER NOT NULL,
`packet_id` BIGINT NOT NULL,
`channel_id` VARCHAR(191) NOT NULL,
`gateway_id` BIGINT NULL,
`text` VARCHAR(191) NOT NULL,
`rx_time` BIGINT NULL,
`rx_snr` DECIMAL(65, 30) NULL,
`rx_rssi` INTEGER NULL,
`hop_limit` INTEGER NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
INDEX `text_messages_created_at_idx`(`created_at`),
INDEX `text_messages_updated_at_idx`(`updated_at`),
INDEX `text_messages_to_idx`(`to`),
INDEX `text_messages_from_idx`(`from`),
INDEX `text_messages_packet_id_idx`(`packet_id`),
INDEX `text_messages_gateway_id_idx`(`gateway_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

View File

@ -0,0 +1,28 @@
-- CreateTable
CREATE TABLE `waypoints` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`from` BIGINT NOT NULL,
`to` BIGINT NOT NULL,
`waypoint_id` BIGINT NOT NULL,
`latitude` INTEGER NOT NULL,
`longitude` INTEGER NOT NULL,
`expire` BIGINT NULL,
`locked_to` BIGINT NULL,
`name` VARCHAR(191) NULL,
`description` VARCHAR(191) NULL,
`icon` INTEGER NULL,
`channel` INTEGER NOT NULL,
`packet_id` BIGINT NOT NULL,
`channel_id` VARCHAR(191) NOT NULL,
`gateway_id` BIGINT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
INDEX `waypoints_created_at_idx`(`created_at`),
INDEX `waypoints_updated_at_idx`(`updated_at`),
INDEX `waypoints_from_idx`(`from`),
INDEX `waypoints_waypoint_id_idx`(`waypoint_id`),
INDEX `waypoints_packet_id_idx`(`packet_id`),
INDEX `waypoints_gateway_id_idx`(`gateway_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

View File

@ -0,0 +1,19 @@
-- CreateTable
CREATE TABLE `service_envelopes` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`mqtt_topic` VARCHAR(191) NOT NULL,
`channel_id` VARCHAR(191) NOT NULL,
`gateway_id` BIGINT NULL,
`to` BIGINT NOT NULL,
`from` BIGINT NOT NULL,
`protobuf` LONGBLOB NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
INDEX `service_envelopes_created_at_idx`(`created_at`),
INDEX `service_envelopes_updated_at_idx`(`updated_at`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateIndex
CREATE INDEX `waypoints_to_idx` ON `waypoints`(`to`);

View File

@ -0,0 +1,2 @@
-- CreateIndex
CREATE INDEX `service_envelopes_gateway_id_idx` ON `service_envelopes`(`gateway_id`);

View File

@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE `traceroutes` ADD COLUMN `channel` INTEGER NULL,
ADD COLUMN `channel_id` VARCHAR(191) NULL,
ADD COLUMN `gateway_id` BIGINT NULL,
ADD COLUMN `packet_id` BIGINT NULL;

View File

@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE `nodes` ADD COLUMN `neighbour_broadcast_interval_secs` INTEGER NULL,
ADD COLUMN `neighbours` JSON NULL;

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `nodes` ADD COLUMN `neighbours_updated_at` DATETIME(3) NULL;

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `nodes` ADD COLUMN `position_updated_at` DATETIME(3) NULL;

View File

@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE `nodes` ADD COLUMN `mqtt_connection_state` VARCHAR(191) NULL,
ADD COLUMN `mqtt_connection_state_updated_at` DATETIME(3) NULL;

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `nodes` MODIFY `is_licensed` BOOLEAN NULL;

View File

@ -0,0 +1,7 @@
-- AlterTable
ALTER TABLE `nodes` ADD COLUMN `firmware_version` VARCHAR(191) NULL,
ADD COLUMN `has_default_channel` BOOLEAN NULL,
ADD COLUMN `modem_preset` INTEGER NULL,
ADD COLUMN `num_online_local_nodes` INTEGER NULL,
ADD COLUMN `position_precision` INTEGER NULL,
ADD COLUMN `region` INTEGER NULL;

View File

@ -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`);

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `nodes` ADD COLUMN `uptime_seconds` BIGINT NULL;

View File

@ -0,0 +1,22 @@
-- CreateTable
CREATE TABLE `positions` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`node_id` BIGINT NOT NULL,
`to` BIGINT NOT NULL,
`from` BIGINT NOT NULL,
`channel` INTEGER NULL,
`packet_id` BIGINT NULL,
`channel_id` VARCHAR(191) NULL,
`gateway_id` BIGINT NULL,
`latitude` INTEGER NULL,
`longitude` INTEGER NULL,
`altitude` INTEGER NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
INDEX `positions_created_at_idx`(`created_at`),
INDEX `positions_updated_at_idx`(`updated_at`),
INDEX `positions_node_id_idx`(`node_id`),
INDEX `positions_packet_id_idx`(`packet_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

View File

@ -0,0 +1,21 @@
-- CreateTable
CREATE TABLE `environment_metrics` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`node_id` BIGINT NOT NULL,
`packet_id` BIGINT NULL,
`temperature` DECIMAL(65, 30) NULL,
`relative_humidity` DECIMAL(65, 30) NULL,
`barometric_pressure` DECIMAL(65, 30) NULL,
`gas_resistance` DECIMAL(65, 30) NULL,
`voltage` DECIMAL(65, 30) NULL,
`current` DECIMAL(65, 30) NULL,
`iaq` INTEGER NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
INDEX `environment_metrics_created_at_idx`(`created_at`),
INDEX `environment_metrics_updated_at_idx`(`updated_at`),
INDEX `environment_metrics_node_id_idx`(`node_id`),
INDEX `environment_metrics_packet_id_idx`(`packet_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

View File

@ -0,0 +1,20 @@
-- CreateTable
CREATE TABLE `power_metrics` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`node_id` BIGINT NOT NULL,
`packet_id` BIGINT NULL,
`ch1_voltage` DECIMAL(65, 30) NULL,
`ch1_current` DECIMAL(65, 30) NULL,
`ch2_voltage` DECIMAL(65, 30) NULL,
`ch2_current` DECIMAL(65, 30) NULL,
`ch3_voltage` DECIMAL(65, 30) NULL,
`ch3_current` DECIMAL(65, 30) NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
INDEX `power_metrics_created_at_idx`(`created_at`),
INDEX `power_metrics_updated_at_idx`(`updated_at`),
INDEX `power_metrics_node_id_idx`(`node_id`),
INDEX `power_metrics_packet_id_idx`(`packet_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

View File

@ -0,0 +1,4 @@
-- AlterTable
ALTER TABLE `nodes` ADD COLUMN `barometric_pressure` DECIMAL(65, 30) NULL,
ADD COLUMN `relative_humidity` DECIMAL(65, 30) NULL,
ADD COLUMN `temperature` DECIMAL(65, 30) NULL;

View File

@ -0,0 +1,8 @@
/*
Warnings:
- You are about to drop the column `mqtt_connection_state` on the `nodes` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE `nodes` DROP COLUMN `mqtt_connection_state`;

View File

@ -0,0 +1,4 @@
-- AlterTable
ALTER TABLE `traceroutes` ADD COLUMN `route_back` JSON NULL,
ADD COLUMN `snr_back` JSON NULL,
ADD COLUMN `snr_towards` JSON NULL;

View File

@ -0,0 +1,2 @@
-- CreateIndex
CREATE INDEX `nodes_position_updated_at_idx` ON `nodes`(`position_updated_at`);

View File

@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE `environment_metrics` ADD COLUMN `wind_direction` INTEGER NULL,
ADD COLUMN `wind_gust` DECIMAL(65, 30) NULL,
ADD COLUMN `wind_lull` DECIMAL(65, 30) NULL,
ADD COLUMN `wind_speed` DECIMAL(65, 30) NULL;

View File

@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "mysql"

298
common/prisma/schema.prisma Normal file
View File

@ -0,0 +1,298 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model Node {
id BigInt @id @default(autoincrement())
node_id BigInt @unique
long_name String
short_name String
hardware_model Int
role Int
is_licensed Boolean?
firmware_version String?
region Int?
modem_preset Int?
has_default_channel Boolean?
position_precision Int?
num_online_local_nodes Int?
latitude Int?
longitude Int?
altitude Int?
position_updated_at DateTime?
battery_level Int?
voltage Decimal?
channel_utilization Decimal?
air_util_tx Decimal?
uptime_seconds BigInt?
temperature Decimal?
relative_humidity Decimal?
barometric_pressure Decimal?
neighbour_broadcast_interval_secs Int?
neighbours Json?
neighbours_updated_at DateTime?
// this column tracks when an mqtt gateway node uplinked a packet
mqtt_connection_state_updated_at DateTime?
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
@@index(created_at)
@@index(updated_at)
@@index(position_updated_at)
@@index(node_id)
@@map("nodes")
}
model MapReport {
id BigInt @id @default(autoincrement())
node_id BigInt
long_name String
short_name String
role Int
hardware_model Int
firmware_version String
region Int?
modem_preset Int?
has_default_channel Boolean?
latitude Int?
longitude Int?
altitude Int?
position_precision Int?
num_online_local_nodes Int?
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
@@index(created_at)
@@index(updated_at)
@@index(node_id)
@@map("map_reports")
}
model NeighbourInfo {
id BigInt @id @default(autoincrement())
node_id BigInt
node_broadcast_interval_secs Int
neighbours Json
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
@@index(created_at)
@@index(updated_at)
@@index(node_id)
@@map("neighbour_infos")
}
model DeviceMetric {
id BigInt @id @default(autoincrement())
node_id BigInt
battery_level Int?
voltage Decimal?
channel_utilization Decimal?
air_util_tx Decimal?
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
@@index(created_at)
@@index(updated_at)
@@index(node_id)
@@map("device_metrics")
}
model EnvironmentMetric {
id BigInt @id @default(autoincrement())
node_id BigInt
packet_id BigInt?
temperature Decimal?
relative_humidity Decimal?
barometric_pressure Decimal?
gas_resistance Decimal?
voltage Decimal?
current Decimal?
iaq Int?
wind_direction Int?
wind_speed Decimal?
wind_gust Decimal?
wind_lull Decimal?
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
@@index(created_at)
@@index(updated_at)
@@index(node_id)
@@index(packet_id)
@@map("environment_metrics")
}
model PowerMetric {
id BigInt @id @default(autoincrement())
node_id BigInt
packet_id BigInt?
ch1_voltage Decimal?
ch1_current Decimal?
ch2_voltage Decimal?
ch2_current Decimal?
ch3_voltage Decimal?
ch3_current Decimal?
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
@@index(created_at)
@@index(updated_at)
@@index(node_id)
@@index(packet_id)
@@map("power_metrics")
}
model Position {
id BigInt @id @default(autoincrement())
node_id BigInt
to BigInt
from BigInt
channel Int?
packet_id BigInt?
channel_id String?
gateway_id BigInt?
latitude Int?
longitude Int?
altitude Int?
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
@@index(created_at)
@@index(updated_at)
@@index(node_id)
@@index(packet_id)
@@map("positions")
}
model ServiceEnvelope {
id BigInt @id @default(autoincrement())
mqtt_topic String
channel_id String
gateway_id BigInt?
to BigInt
from BigInt
protobuf Bytes
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
@@index(created_at)
@@index(updated_at)
@@index(gateway_id)
@@map("service_envelopes")
}
model TextMessage {
id BigInt @id @default(autoincrement())
to BigInt
from BigInt
channel Int
packet_id BigInt
channel_id String
gateway_id BigInt?
text String
rx_time BigInt?
rx_snr Decimal?
rx_rssi Int?
hop_limit Int?
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
@@index(created_at)
@@index(updated_at)
@@index(to)
@@index(from)
@@index(packet_id)
@@index(gateway_id)
@@map("text_messages")
}
model TraceRoute {
id BigInt @id @default(autoincrement())
to BigInt
from BigInt
want_response Boolean
route Json
snr_towards Json?
route_back Json?
snr_back Json?
channel Int?
packet_id BigInt?
channel_id String?
gateway_id BigInt?
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
@@index(created_at)
@@index(updated_at)
@@index(to)
@@index(from)
@@map("traceroutes")
}
model Waypoint {
id BigInt @id @default(autoincrement())
from BigInt
to BigInt
waypoint_id BigInt
latitude Int
longitude Int
expire BigInt?
locked_to BigInt?
name String?
description String?
icon Int?
channel Int
packet_id BigInt
channel_id String
gateway_id BigInt?
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
@@index(created_at)
@@index(updated_at)
@@index(to)
@@index(from)
@@index(waypoint_id)
@@index(packet_id)
@@index(gateway_id)
@@map("waypoints")
}