/*
  Warnings:

  - You are about to drop the `MaintenanceChecklist` table. If the table is not empty, all the data it contains will be lost.

*/
-- DropForeignKey
ALTER TABLE "MaintenanceChecklist" DROP CONSTRAINT "MaintenanceChecklist_signedById_fkey";

-- DropForeignKey
ALTER TABLE "MaintenanceChecklist" DROP CONSTRAINT "MaintenanceChecklist_taskId_fkey";

-- DropTable
DROP TABLE "MaintenanceChecklist";

-- CreateTable
CREATE TABLE "MaintenanceLog" (
    "id" TEXT NOT NULL,
    "taskId" TEXT NOT NULL,
    "type" TEXT NOT NULL,
    "description" TEXT NOT NULL,
    "hours" DOUBLE PRECISION,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "createdById" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "MaintenanceLogPart" (
    "id" TEXT NOT NULL,
    "logId" TEXT NOT NULL,
    "partNumber" TEXT NOT NULL,
    "quantity" INTEGER NOT NULL,
    "action" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE INDEX "MaintenanceLog_taskId_idx" ON "MaintenanceLog"("taskId");

-- CreateIndex
CREATE INDEX "MaintenanceLog_createdById_idx" ON "MaintenanceLog"("createdById");

-- CreateIndex
CREATE INDEX "MaintenanceLogPart_logId_idx" ON "MaintenanceLogPart"("logId");

-- CreateIndex
CREATE INDEX "MaintenanceLogPart_partNumber_idx" ON "MaintenanceLogPart"("partNumber");

-- AddForeignKey
ALTER TABLE "MaintenanceLog" ADD CONSTRAINT "MaintenanceLog_taskId_fkey" FOREIGN KEY ("taskId") REFERENCES "MaintenanceTask"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MaintenanceLog" ADD CONSTRAINT "MaintenanceLog_createdById_fkey" FOREIGN KEY ("createdById") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MaintenanceLogPart" ADD CONSTRAINT "MaintenanceLogPart_logId_fkey" FOREIGN KEY ("logId") REFERENCES "MaintenanceLog"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
