/*
  Warnings:

  - Added the required column `virtualMachineId` to the `ServerMonitoringSettings` table without a default value. This is not possible if the table is not empty.

*/
-- AlterTable
ALTER TABLE "ServerMonitoringSettings" ADD COLUMN     "virtualMachineId" INTEGER NOT NULL;

-- CreateTable
CREATE TABLE "virtual_machines" (
    "id" SERIAL NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "serverId" INTEGER NOT NULL,
    "icon" TEXT,
    "ipv4Address" TEXT,
    "osDetails" TEXT,
    "cpuDetails" TEXT,
    "gpuDetails" TEXT,
    "memoryDetails" TEXT,
    "storageDetails" TEXT,
    "managementUrl" TEXT,
    "monitoring" BOOLEAN NOT NULL DEFAULT false,
    "monitoringUrl" TEXT,

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

-- CreateTable
CREATE TABLE "virtual_machine_monitoring" (
    "id" SERIAL NOT NULL,
    "virtualMachineId" INTEGER NOT NULL,
    "cpuPercentUsage" DOUBLE PRECISION NOT NULL,
    "gpuPercentUsage" DOUBLE PRECISION NOT NULL,
    "memoryUsage" DOUBLE PRECISION NOT NULL,
    "memoryPercentUsage" DOUBLE PRECISION NOT NULL,
    "diskUsage" DOUBLE PRECISION NOT NULL,
    "diskPercentUsage" DOUBLE PRECISION NOT NULL,
    "online" BOOLEAN NOT NULL,
    "uptimeSeconds" INTEGER NOT NULL,
    "timestamp" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE INDEX "virtual_machine_monitoring_virtualMachineId_timestamp_idx" ON "virtual_machine_monitoring"("virtualMachineId", "timestamp");

-- CreateIndex
CREATE INDEX "virtual_machine_monitoring_online_idx" ON "virtual_machine_monitoring"("online");

-- AddForeignKey
ALTER TABLE "virtual_machines" ADD CONSTRAINT "virtual_machines_serverId_fkey" FOREIGN KEY ("serverId") REFERENCES "servers"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "virtual_machine_monitoring" ADD CONSTRAINT "virtual_machine_monitoring_virtualMachineId_fkey" FOREIGN KEY ("virtualMachineId") REFERENCES "virtual_machines"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ServerMonitoringSettings" ADD CONSTRAINT "ServerMonitoringSettings_virtualMachineId_fkey" FOREIGN KEY ("virtualMachineId") REFERENCES "virtual_machines"("id") ON DELETE CASCADE ON UPDATE CASCADE;
