/*
  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     "encryptedSshPassword" TEXT,
ADD COLUMN     "encryptedSshUser" TEXT,
ADD COLUMN     "inventoryTag" TEXT;

-- AlterTable
ALTER TABLE "WifiDevice" ADD COLUMN     "frequency" TEXT,
ADD COLUMN     "identity" TEXT,
ADD COLUMN     "name" TEXT,
ADD COLUMN     "notes" 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,
    "avgSignal" INTEGER,
    "minSignal" INTEGER,
    "maxSignal" INTEGER,
    "avgSpeed" INTEGER,
    "minSpeed" INTEGER,
    "maxSpeed" INTEGER,
    "avgClientUptime" INTEGER,
    "maxClientUptime" INTEGER,
    "avgUsage" INTEGER,
    "sumUsage" INTEGER,
    "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;
