-- DropForeignKey
ALTER TABLE "PAHost" DROP CONSTRAINT "PAHost_ownerId_fkey";

-- DropForeignKey
ALTER TABLE "ResetToken" DROP CONSTRAINT "ResetToken_creatorId_fkey";

-- DropForeignKey
ALTER TABLE "ResetToken" DROP CONSTRAINT "ResetToken_userId_fkey";

-- AlterTable
ALTER TABLE "WifiDevice" ADD COLUMN     "accessPointId" INTEGER;

-- CreateTable
CREATE TABLE "AccessPoint" (
    "id" SERIAL NOT NULL,
    "mac" TEXT NOT NULL,
    "hostname" TEXT NOT NULL,
    "name" TEXT,
    "local" TEXT,
    "notes" TEXT,
    "uptime" TEXT,
    "controller" TEXT,
    "model" TEXT,
    "ip" TEXT,
    "clients" INTEGER,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "AccessPoint_mac_key" ON "AccessPoint"("mac");

-- CreateIndex
CREATE UNIQUE INDEX "AccessPoint_hostname_key" ON "AccessPoint"("hostname");

-- AddForeignKey
ALTER TABLE "ResetToken" ADD CONSTRAINT "ResetToken_creatorId_fkey" FOREIGN KEY ("creatorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ResetToken" ADD CONSTRAINT "ResetToken_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "WifiDevice" ADD CONSTRAINT "WifiDevice_accessPointId_fkey" FOREIGN KEY ("accessPointId") REFERENCES "AccessPoint"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PAHost" ADD CONSTRAINT "PAHost_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- RenameIndex
ALTER INDEX "PAHost.cidr_unique" RENAME TO "PAHost_cidr_key";

-- RenameIndex
ALTER INDEX "ResetToken.token_unique" RENAME TO "ResetToken_token_key";

-- RenameIndex
ALTER INDEX "User.sAMAccountName_unique" RENAME TO "User_sAMAccountName_key";

-- RenameIndex
ALTER INDEX "WifiDevice.mac_unique" RENAME TO "WifiDevice_mac_key";
