-- CreateTable
CREATE TABLE "BatteryAlert" (
    "id" TEXT NOT NULL,
    "deviceId" TEXT NOT NULL,
    "threshold" INTEGER NOT NULL DEFAULT 20,
    "notifyNumber" TEXT NOT NULL,
    "message" TEXT,
    "enabled" BOOLEAN NOT NULL DEFAULT true,
    "lastBelow" BOOLEAN,
    "lastNotifiedAt" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "BatteryAlert_deviceId_key" ON "BatteryAlert"("deviceId");

-- AddForeignKey
ALTER TABLE "BatteryAlert" ADD CONSTRAINT "BatteryAlert_deviceId_fkey" FOREIGN KEY ("deviceId") REFERENCES "Device"("id") ON DELETE CASCADE ON UPDATE CASCADE;

