Prepare DB for new feature
This commit is contained in:
parent
bc4fab24c1
commit
7333981b2c
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -10,3 +10,4 @@ pti.code-workspace
|
|||
temporary-captain-to-deploy.tar
|
||||
deploy.sh
|
||||
output.json
|
||||
client_sample.json
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the `Statistic` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "AccessPoint" ADD COLUMN "inventoryTag" TEXT,
|
||||
ADD COLUMN "sshPassword" TEXT,
|
||||
ADD COLUMN "sshUser" TEXT;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "WifiDevice" ADD COLUMN "frequency" TEXT,
|
||||
ADD COLUMN "identity" TEXT,
|
||||
ADD COLUMN "ownerId" INTEGER,
|
||||
ADD COLUMN "protocol" TEXT,
|
||||
ADD COLUMN "signalStrength" INTEGER,
|
||||
ADD COLUMN "speed" INTEGER,
|
||||
ADD COLUMN "usage" INTEGER;
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "Statistic";
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "WifiStats" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"timestamp" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"clients" INTEGER NOT NULL,
|
||||
"accessPointId" INTEGER NOT NULL,
|
||||
|
||||
CONSTRAINT "WifiStats_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Network" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"shortName" TEXT NOT NULL,
|
||||
"cidr" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "Network_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Network_name_key" ON "Network"("name");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Network_shortName_key" ON "Network"("shortName");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Network_cidr_key" ON "Network"("cidr");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "WifiDevice" ADD CONSTRAINT "WifiDevice_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "WifiStats" ADD CONSTRAINT "WifiStats_accessPointId_fkey" FOREIGN KEY ("accessPointId") REFERENCES "AccessPoint"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
@ -14,10 +14,12 @@ model ResetToken {
|
|||
usedAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
userId Int
|
||||
user User @relation("resettoken_to_user", fields: [userId], references: [id])
|
||||
|
||||
creatorId Int
|
||||
creator User @relation("resettoken_to_creator", fields: [creatorId], references: [id])
|
||||
user User @relation("resettoken_to_user", fields: [userId], references: [id])
|
||||
}
|
||||
|
||||
model User {
|
||||
|
@ -66,9 +68,12 @@ model User {
|
|||
userPrincipalName String?
|
||||
whenChanged String?
|
||||
whenCreated String?
|
||||
|
||||
createdTokens ResetToken[] @relation("resettoken_to_creator")
|
||||
tokens ResetToken[] @relation("resettoken_to_user")
|
||||
wifiDevices WifiDevice[] @relation("wifidevice_to_user")
|
||||
ownedWifiDevices WifiDevice[] @relation("wifidevice_to_owner")
|
||||
|
||||
PAHost PAHost[] @relation("pahost_to_user")
|
||||
}
|
||||
|
||||
|
@ -79,18 +84,32 @@ model WifiDevice {
|
|||
hostname String?
|
||||
firstSeen DateTime? @default(now())
|
||||
lastSeen DateTime?
|
||||
essid String?
|
||||
ip String?
|
||||
|
||||
essid String?
|
||||
uptime String?
|
||||
apName String?
|
||||
accessPointId Int?
|
||||
accessPoint AccessPoint? @relation("wifidevice_to_ap", fields: [accessPointId], references: [id])
|
||||
signalStrength Int?
|
||||
frequency String?
|
||||
protocol String?
|
||||
speed Int?
|
||||
usage Int?
|
||||
|
||||
status Status?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
userId Int?
|
||||
controller String @default("unknown")
|
||||
|
||||
identity String? // The user informed by the controller
|
||||
|
||||
accessPointId Int?
|
||||
accessPoint AccessPoint? @relation("wifidevice_to_ap", fields: [accessPointId], references: [id])
|
||||
|
||||
userId Int? // The connected User
|
||||
user User? @relation("wifidevice_to_user", fields: [userId], references: [id])
|
||||
|
||||
ownerId Int? // The owner of the device
|
||||
owner User? @relation("wifidevice_to_owner", fields: [ownerId], references: [id])
|
||||
}
|
||||
|
||||
enum Status {
|
||||
|
@ -116,16 +135,6 @@ enum LogLevel {
|
|||
ERROR
|
||||
}
|
||||
|
||||
model Statistic {
|
||||
id Int @id @default(autoincrement())
|
||||
timestamp DateTime @default(now())
|
||||
onlineUsers Int
|
||||
offlineUsers Int
|
||||
totalUsers Int
|
||||
totalWifiDevices Int
|
||||
onlineWifiDevices Int
|
||||
}
|
||||
|
||||
model PAHost {
|
||||
id Int @id @default(autoincrement())
|
||||
user String
|
||||
|
@ -147,14 +156,38 @@ model AccessPoint {
|
|||
name String?
|
||||
local String?
|
||||
notes String?
|
||||
inventoryTag String?
|
||||
|
||||
uptime String?
|
||||
controller String?
|
||||
model String?
|
||||
ip String?
|
||||
clients Int?
|
||||
|
||||
sshUser String?
|
||||
sshPassword String?
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
wifiDevices WifiDevice[] @relation("wifidevice_to_ap")
|
||||
WifiStats WifiStats[] @relation("wifistats_to_ap")
|
||||
}
|
||||
|
||||
model WifiStats {
|
||||
id Int @id @default(autoincrement())
|
||||
timestamp DateTime @default(now())
|
||||
clients Int
|
||||
accessPointId Int
|
||||
accessPoint AccessPoint? @relation("wifistats_to_ap", fields: [accessPointId], references: [id])
|
||||
}
|
||||
|
||||
model Network {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @unique
|
||||
shortName String @unique
|
||||
cidr String @unique
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
|
|
@ -105,7 +105,12 @@ export async function getOnlineWifiDevices() {
|
|||
uptime: client.UT.toString(),
|
||||
apName: client.AP,
|
||||
status: client.ST == 'Online' ? 'ONLINE' : 'OFFLINE',
|
||||
controller: 'Cisco'
|
||||
controller: 'Cisco',
|
||||
signalStrength: client.SS,
|
||||
frequency: client.FB,
|
||||
protocol: client.PT,
|
||||
speed: client.SD,
|
||||
usage: client.bytes_total
|
||||
}))
|
||||
|
||||
return restructuredOnlineDevices
|
||||
|
|
|
@ -189,7 +189,12 @@ export async function getOnlineWifiDevices() {
|
|||
uptime: client.uptime.toString(),
|
||||
apName: accessPoints[0].find(ap => ap.mac === client.ap_mac).name,
|
||||
status: 'ONLINE',
|
||||
controller: 'UniFi'
|
||||
controller: 'UniFi',
|
||||
signalStrength: client.signal,
|
||||
frequency: null,
|
||||
protocol: null,
|
||||
speed: client.tx_rate,
|
||||
usage: +client.tx_bytes + +client.rx_bytes
|
||||
}))
|
||||
|
||||
return restructuredOnlineDevices
|
||||
|
|
Loading…
Reference in New Issue
Block a user