/*
  Warnings:

  - The `uptime` column on the `AccessPoint` table would be dropped and recreated. This will lead to data loss if there is data in the column.
  - The `uptime` column on the `WifiDevice` table would be dropped and recreated. This will lead to data loss if there is data in the column.
  - You are about to drop the `WifiStats` table. If the table is not empty, all the data it contains will be lost.

*/
-- DropForeignKey
ALTER TABLE "WifiStats" DROP CONSTRAINT "WifiStats_accessPointId_fkey";

-- AlterTable
ALTER TABLE "AccessPoint" ADD COLUMN     "usage" BIGINT,
DROP COLUMN "uptime",
ADD COLUMN     "uptime" INTEGER;

-- AlterTable
ALTER TABLE "WifiDevice" DROP COLUMN "uptime",
ADD COLUMN     "uptime" INTEGER,
ALTER COLUMN "usage" SET DATA TYPE BIGINT;

-- DropTable
DROP TABLE "WifiStats";

-- CreateTable
CREATE TABLE "AccessPointStats" (
    "id" SERIAL NOT NULL,
    "timestamp" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "clients" INTEGER,
    "avgSignalStrength" INTEGER,
    "minSignalStrength" INTEGER,
    "maxSignalStrength" INTEGER,
    "avgSpeed" INTEGER,
    "minSpeed" INTEGER,
    "maxSpeed" INTEGER,
    "avgClientUptime" INTEGER,
    "maxClientUptime" INTEGER,
    "avgUsage" BIGINT,
    "sumUsage" BIGINT,
    "accessPointId" INTEGER NOT NULL,

    CONSTRAINT "AccessPointStats_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "AccessPointStats" ADD CONSTRAINT "AccessPointStats_accessPointId_fkey" FOREIGN KEY ("accessPointId") REFERENCES "AccessPoint"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
