-- CreateTable
CREATE TABLE "Geofence" (
    "id" TEXT NOT NULL,
    "deviceId" TEXT NOT NULL,
    "refLat" DOUBLE PRECISION NOT NULL,
    "refLng" DOUBLE PRECISION NOT NULL,
    "radiusM" INTEGER NOT NULL DEFAULT 50,
    "notifyNumber" TEXT NOT NULL,
    "enabled" BOOLEAN NOT NULL DEFAULT true,
    "lastInside" BOOLEAN,
    "lastNotifiedAt" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "Geofence_deviceId_key" ON "Geofence"("deviceId");

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

