/*
  Warnings:

  - You are about to drop the column `currency` on the `InventoryItem` table. All the data in the column will be lost.
  - You are about to drop the column `currentStock` on the `InventoryItem` table. All the data in the column will be lost.
  - You are about to drop the column `isLRU` on the `InventoryItem` table. All the data in the column will be lost.
  - You are about to drop the column `lastUpdated` on the `InventoryItem` table. All the data in the column will be lost.
  - You are about to drop the column `minimumStock` on the `InventoryItem` table. All the data in the column will be lost.
  - You are about to drop the column `price` on the `InventoryItem` table. All the data in the column will be lost.
  - You are about to drop the column `unitOfMeasure` on the `InventoryItem` table. All the data in the column will be lost.
  - You are about to drop the column `frequency` on the `MaintenanceSchedule` table. All the data in the column will be lost.
  - You are about to drop the column `intervalCycles` on the `MaintenanceSchedule` table. All the data in the column will be lost.
  - You are about to drop the column `intervalDays` on the `MaintenanceSchedule` table. All the data in the column will be lost.
  - You are about to drop the column `intervalHours` on the `MaintenanceSchedule` table. All the data in the column will be lost.
  - You are about to drop the column `lastPerformed` on the `MaintenanceSchedule` table. All the data in the column will be lost.
  - You are about to drop the column `nextDue` on the `MaintenanceSchedule` table. All the data in the column will be lost.
  - You are about to drop the column `reminderDays` on the `MaintenanceSchedule` table. All the data in the column will be lost.
  - You are about to drop the column `taskId` on the `MaintenanceSchedule` table. All the data in the column will be lost.
  - You are about to drop the column `actualEndDate` on the `MaintenanceTask` table. All the data in the column will be lost.
  - You are about to drop the column `actualStartDate` on the `MaintenanceTask` table. All the data in the column will be lost.
  - You are about to drop the column `assignedToId` on the `MaintenanceTask` table. All the data in the column will be lost.
  - You are about to drop the column `plannedEndDate` on the `MaintenanceTask` table. All the data in the column will be lost.
  - You are about to drop the column `plannedStartDate` on the `MaintenanceTask` table. All the data in the column will be lost.
  - You are about to drop the column `taskNumber` on the `MaintenanceTask` table. All the data in the column will be lost.
  - You are about to drop the column `type` on the `MaintenanceTask` table. All the data in the column will be lost.
  - The `priority` column on the `MaintenanceTask` table would be dropped and recreated. This will lead to data loss if there is data in the column.
  - The `status` column on the `MaintenanceTask` table would be dropped and recreated. This will lead to data loss if there is data in the column.
  - You are about to drop the column `assetId` on the `WorkOrder` table. All the data in the column will be lost.
  - You are about to drop the column `assignedTo` on the `WorkOrder` table. All the data in the column will be lost.
  - You are about to drop the column `catalogId` on the `WorkOrder` table. All the data in the column will be lost.
  - You are about to drop the column `createdBy` on the `WorkOrder` table. All the data in the column will be lost.
  - You are about to drop the column `updatedBy` on the `WorkOrder` table. All the data in the column will be lost.
  - The `priority` column on the `WorkOrder` table would be dropped and recreated. This will lead to data loss if there is data in the column.
  - The `status` column on the `WorkOrder` table would be dropped and recreated. This will lead to data loss if there is data in the column.
  - You are about to drop the column `createdAt` on the `WorkOrderAttachment` table. All the data in the column will be lost.
  - You are about to drop the column `createdBy` on the `WorkOrderAttachment` table. All the data in the column will be lost.
  - You are about to drop the column `taskId` on the `WorkOrderAttachment` table. All the data in the column will be lost.
  - You are about to drop the `ComponentHistory` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `ComponentTracking` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `DefectPart` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `DefectRecord` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `InspectionCatalog` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `InspectionPart` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `InspectionResource` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `InspectionTask` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `MaintenanceChecklist` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `MaintenanceLog` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `WorkOrderSubtask` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `WorkOrderTask` table. If the table is not empty, all the data it contains will be lost.
  - Added the required column `updatedAt` to the `InventoryItem` table without a default value. This is not possible if the table is not empty.
  - Added the required column `createdById` to the `MaintenanceSchedule` table without a default value. This is not possible if the table is not empty.
  - Added the required column `endDate` to the `MaintenanceSchedule` table without a default value. This is not possible if the table is not empty.
  - Added the required column `startDate` to the `MaintenanceSchedule` table without a default value. This is not possible if the table is not empty.
  - Added the required column `title` to the `MaintenanceSchedule` table without a default value. This is not possible if the table is not empty.
  - Added the required column `type` to the `MaintenanceSchedule` table without a default value. This is not possible if the table is not empty.
  - Added the required column `dueDate` to the `MaintenanceTask` table without a default value. This is not possible if the table is not empty.
  - Added the required column `workOrderId` to the `MaintenanceTask` table without a default value. This is not possible if the table is not empty.
  - Changed the type of `type` on the `WorkOrder` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
  - Made the column `assetType` on table `WorkOrder` required. This step will fail if there are existing NULL values in that column.
  - Added the required column `size` to the `WorkOrderAttachment` table without a default value. This is not possible if the table is not empty.
  - Added the required column `uploadedBy` to the `WorkOrderAttachment` table without a default value. This is not possible if the table is not empty.

*/
-- CreateEnum
CREATE TYPE "MaintenancePriority" AS ENUM ('HIGH', 'MEDIUM', 'LOW');

-- CreateEnum
CREATE TYPE "MaintenanceType" AS ENUM ('PREVENTIVE', 'CORRECTIVE', 'INSPECTION', 'MODIFICATION', 'OVERHAUL');

-- CreateEnum
CREATE TYPE "ScheduleStatus" AS ENUM ('DRAFT', 'PUBLISHED', 'IN_PROGRESS', 'COMPLETED', 'CANCELLED');

-- CreateEnum
CREATE TYPE "WorkOrderStatus" AS ENUM ('DRAFT', 'ASSIGNED', 'IN_PROGRESS', 'ON_HOLD', 'COMPLETED', 'CLOSED', 'CANCELLED');

-- CreateEnum
CREATE TYPE "TaskStatus" AS ENUM ('PENDING', 'IN_PROGRESS', 'COMPLETED', 'DEFERRED', 'CANCELLED');

-- CreateEnum
CREATE TYPE "SubtaskStatus" AS ENUM ('PENDING', 'COMPLETED');

-- CreateEnum
CREATE TYPE "SignoffType" AS ENUM ('TECHNICIAN', 'INSPECTOR', 'SUPERVISOR');

-- CreateEnum
CREATE TYPE "StaffStatus" AS ENUM ('ACTIVE', 'ON_LEAVE', 'INACTIVE', 'TERMINATED');

-- DropForeignKey
ALTER TABLE "ComponentHistory" DROP CONSTRAINT "ComponentHistory_trackingId_fkey";

-- DropForeignKey
ALTER TABLE "ComponentTracking" DROP CONSTRAINT "ComponentTracking_componentId_fkey";

-- DropForeignKey
ALTER TABLE "DefectPart" DROP CONSTRAINT "DefectPart_defectId_fkey";

-- DropForeignKey
ALTER TABLE "DefectRecord" DROP CONSTRAINT "DefectRecord_aircraftId_fkey";

-- DropForeignKey
ALTER TABLE "DefectRecord" DROP CONSTRAINT "DefectRecord_workOrderId_fkey";

-- DropForeignKey
ALTER TABLE "InspectionPart" DROP CONSTRAINT "InspectionPart_catalogId_fkey";

-- DropForeignKey
ALTER TABLE "InspectionResource" DROP CONSTRAINT "InspectionResource_catalogId_fkey";

-- DropForeignKey
ALTER TABLE "InspectionTask" DROP CONSTRAINT "InspectionTask_catalogId_fkey";

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

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

-- DropForeignKey
ALTER TABLE "MaintenanceLog" DROP CONSTRAINT "MaintenanceLog_createdById_fkey";

-- DropForeignKey
ALTER TABLE "MaintenanceLog" DROP CONSTRAINT "MaintenanceLog_taskId_fkey";

-- DropForeignKey
ALTER TABLE "MaintenanceSchedule" DROP CONSTRAINT "MaintenanceSchedule_taskId_fkey";

-- DropForeignKey
ALTER TABLE "MaintenanceTask" DROP CONSTRAINT "MaintenanceTask_aircraftId_fkey";

-- DropForeignKey
ALTER TABLE "MaintenanceTask" DROP CONSTRAINT "MaintenanceTask_assignedToId_fkey";

-- DropForeignKey
ALTER TABLE "WorkOrder" DROP CONSTRAINT "WorkOrder_catalogId_fkey";

-- DropForeignKey
ALTER TABLE "WorkOrderAttachment" DROP CONSTRAINT "WorkOrderAttachment_taskId_fkey";

-- DropForeignKey
ALTER TABLE "WorkOrderSubtask" DROP CONSTRAINT "WorkOrderSubtask_taskId_fkey";

-- DropForeignKey
ALTER TABLE "WorkOrderTask" DROP CONSTRAINT "WorkOrderTask_workOrderId_fkey";

-- DropIndex
DROP INDEX "MaintenanceSchedule_taskId_idx";

-- DropIndex
DROP INDEX "MaintenanceSchedule_taskId_key";

-- DropIndex
DROP INDEX "MaintenanceTask_assignedToId_idx";

-- DropIndex
DROP INDEX "MaintenanceTask_taskNumber_key";

-- DropIndex
DROP INDEX "WorkOrder_assetId_idx";

-- DropIndex
DROP INDEX "WorkOrder_assetType_idx";

-- DropIndex
DROP INDEX "WorkOrder_number_idx";

-- DropIndex
DROP INDEX "WorkOrder_status_idx";

-- AlterTable
ALTER TABLE "InventoryItem" DROP COLUMN "currency",
DROP COLUMN "currentStock",
DROP COLUMN "isLRU",
DROP COLUMN "lastUpdated",
DROP COLUMN "minimumStock",
DROP COLUMN "price",
DROP COLUMN "unitOfMeasure",
ADD COLUMN     "attachments" JSONB,
ADD COLUMN     "condition" TEXT NOT NULL DEFAULT 'new',
ADD COLUMN     "expiryDate" TIMESTAMP(3),
ADD COLUMN     "lastChecked" TIMESTAMP(3),
ADD COLUMN     "maxQuantity" INTEGER,
ADD COLUMN     "minQuantity" INTEGER NOT NULL DEFAULT 0,
ADD COLUMN     "notes" TEXT,
ADD COLUMN     "quantity" INTEGER NOT NULL DEFAULT 0,
ADD COLUMN     "serialNumber" TEXT,
ADD COLUMN     "totalValue" DOUBLE PRECISION,
ADD COLUMN     "unitPrice" DOUBLE PRECISION,
ADD COLUMN     "updatedAt" TIMESTAMP(3) NOT NULL,
ALTER COLUMN "manufacturer" DROP NOT NULL,
ALTER COLUMN "location" DROP NOT NULL,
ALTER COLUMN "status" SET DEFAULT 'active';

-- AlterTable
ALTER TABLE "MaintenanceSchedule" DROP COLUMN "frequency",
DROP COLUMN "intervalCycles",
DROP COLUMN "intervalDays",
DROP COLUMN "intervalHours",
DROP COLUMN "lastPerformed",
DROP COLUMN "nextDue",
DROP COLUMN "reminderDays",
DROP COLUMN "taskId",
ADD COLUMN     "aircraftId" TEXT,
ADD COLUMN     "createdById" TEXT NOT NULL,
ADD COLUMN     "description" TEXT,
ADD COLUMN     "endDate" TIMESTAMP(3) NOT NULL,
ADD COLUMN     "priority" "MaintenancePriority" NOT NULL DEFAULT 'MEDIUM',
ADD COLUMN     "startDate" TIMESTAMP(3) NOT NULL,
ADD COLUMN     "status" "ScheduleStatus" NOT NULL DEFAULT 'DRAFT',
ADD COLUMN     "title" TEXT NOT NULL,
ADD COLUMN     "type" "MaintenanceType" NOT NULL;

-- AlterTable
ALTER TABLE "MaintenanceTask" DROP COLUMN "actualEndDate",
DROP COLUMN "actualStartDate",
DROP COLUMN "assignedToId",
DROP COLUMN "plannedEndDate",
DROP COLUMN "plannedStartDate",
DROP COLUMN "taskNumber",
DROP COLUMN "type",
ADD COLUMN     "assignedUserId" TEXT,
ADD COLUMN     "completedDate" TIMESTAMP(3),
ADD COLUMN     "dueDate" TIMESTAMP(3) NOT NULL,
ADD COLUMN     "instructions" TEXT[],
ADD COLUMN     "startDate" TIMESTAMP(3),
ADD COLUMN     "supervisorId" TEXT,
ADD COLUMN     "workOrderId" TEXT NOT NULL,
DROP COLUMN "priority",
ADD COLUMN     "priority" "MaintenancePriority" NOT NULL DEFAULT 'MEDIUM',
DROP COLUMN "status",
ADD COLUMN     "status" "TaskStatus" NOT NULL DEFAULT 'PENDING',
ALTER COLUMN "description" DROP NOT NULL,
ALTER COLUMN "aircraftId" DROP NOT NULL,
ALTER COLUMN "estimatedHours" DROP NOT NULL;

-- AlterTable
ALTER TABLE "StockMovement" ADD COLUMN     "receiptId" TEXT;

-- AlterTable
ALTER TABLE "WorkOrder" DROP COLUMN "assetId",
DROP COLUMN "assignedTo",
DROP COLUMN "catalogId",
DROP COLUMN "createdBy",
DROP COLUMN "updatedBy",
ADD COLUMN     "actualHours" DOUBLE PRECISION,
ADD COLUMN     "aircraftId" TEXT,
ADD COLUMN     "estimatedHours" DOUBLE PRECISION,
ADD COLUMN     "scheduleId" TEXT,
DROP COLUMN "priority",
ADD COLUMN     "priority" "MaintenancePriority" NOT NULL DEFAULT 'MEDIUM',
DROP COLUMN "status",
ADD COLUMN     "status" "WorkOrderStatus" NOT NULL DEFAULT 'DRAFT',
DROP COLUMN "type",
ADD COLUMN     "type" "MaintenanceType" NOT NULL,
ALTER COLUMN "assetType" SET NOT NULL;

-- AlterTable
ALTER TABLE "WorkOrderAttachment" DROP COLUMN "createdAt",
DROP COLUMN "createdBy",
DROP COLUMN "taskId",
ADD COLUMN     "size" INTEGER NOT NULL,
ADD COLUMN     "uploadedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN     "uploadedBy" TEXT NOT NULL;

-- DropTable
DROP TABLE "ComponentHistory";

-- DropTable
DROP TABLE "ComponentTracking";

-- DropTable
DROP TABLE "DefectPart";

-- DropTable
DROP TABLE "DefectRecord";

-- DropTable
DROP TABLE "InspectionCatalog";

-- DropTable
DROP TABLE "InspectionPart";

-- DropTable
DROP TABLE "InspectionResource";

-- DropTable
DROP TABLE "InspectionTask";

-- DropTable
DROP TABLE "MaintenanceChecklist";

-- DropTable
DROP TABLE "MaintenanceLog";

-- DropTable
DROP TABLE "WorkOrderSubtask";

-- DropTable
DROP TABLE "WorkOrderTask";

-- DropEnum
DROP TYPE "DefectSeverity";

-- DropEnum
DROP TYPE "DefectStatus";

-- DropEnum
DROP TYPE "DiscoveryPhase";

-- DropEnum
DROP TYPE "InstalledStatus";

-- DropEnum
DROP TYPE "MaintenanceTaskPriority";

-- DropEnum
DROP TYPE "MaintenanceTaskStatus";

-- DropEnum
DROP TYPE "MaintenanceTaskType";

-- DropEnum
DROP TYPE "TrackingSince";

-- CreateTable
CREATE TABLE "Staff" (
    "id" TEXT NOT NULL,
    "employeeId" TEXT NOT NULL,
    "firstName" TEXT NOT NULL,
    "lastName" TEXT NOT NULL,
    "email" TEXT NOT NULL,
    "phone" TEXT,
    "position" TEXT NOT NULL,
    "department" TEXT NOT NULL,
    "licenseNumber" TEXT,
    "licenseType" TEXT,
    "licenseExpiry" TIMESTAMP(3),
    "qualifications" TEXT[],
    "status" "StaffStatus" NOT NULL DEFAULT 'ACTIVE',
    "joinDate" TIMESTAMP(3) NOT NULL,
    "endDate" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "Subtask" (
    "id" TEXT NOT NULL,
    "taskId" TEXT NOT NULL,
    "title" TEXT NOT NULL,
    "description" TEXT,
    "status" "SubtaskStatus" NOT NULL DEFAULT 'PENDING',
    "completedById" TEXT,
    "completedAt" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "RequiredPart" (
    "id" TEXT NOT NULL,
    "taskId" TEXT NOT NULL,
    "partId" TEXT NOT NULL,
    "quantity" INTEGER NOT NULL,
    "issued" BOOLEAN NOT NULL DEFAULT false,
    "issuedById" TEXT,
    "issuedAt" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "RequiredTool" (
    "id" TEXT NOT NULL,
    "taskId" TEXT NOT NULL,
    "toolId" TEXT NOT NULL,
    "quantity" INTEGER NOT NULL,
    "checkedOut" BOOLEAN NOT NULL DEFAULT false,
    "checkedOutById" TEXT,
    "checkedOutAt" TIMESTAMP(3),
    "returnedAt" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "TaskAttachment" (
    "id" TEXT NOT NULL,
    "taskId" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "type" TEXT NOT NULL,
    "url" TEXT NOT NULL,
    "size" INTEGER NOT NULL,
    "uploadedById" TEXT NOT NULL,
    "uploadedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "TaskSignoff" (
    "id" TEXT NOT NULL,
    "taskId" TEXT NOT NULL,
    "type" "SignoffType" NOT NULL,
    "signedById" TEXT NOT NULL,
    "signedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "remarks" TEXT,

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

-- CreateTable
CREATE TABLE "_StaffWorkOrders" (
    "A" TEXT NOT NULL,
    "B" TEXT NOT NULL,

    CONSTRAINT "_StaffWorkOrders_AB_pkey" PRIMARY KEY ("A","B")
);

-- CreateTable
CREATE TABLE "_AssignedStaff" (
    "A" TEXT NOT NULL,
    "B" TEXT NOT NULL,

    CONSTRAINT "_AssignedStaff_AB_pkey" PRIMARY KEY ("A","B")
);

-- CreateIndex
CREATE UNIQUE INDEX "Staff_employeeId_key" ON "Staff"("employeeId");

-- CreateIndex
CREATE UNIQUE INDEX "Staff_email_key" ON "Staff"("email");

-- CreateIndex
CREATE INDEX "Staff_employeeId_idx" ON "Staff"("employeeId");

-- CreateIndex
CREATE INDEX "Staff_email_idx" ON "Staff"("email");

-- CreateIndex
CREATE INDEX "Staff_status_idx" ON "Staff"("status");

-- CreateIndex
CREATE INDEX "Subtask_taskId_idx" ON "Subtask"("taskId");

-- CreateIndex
CREATE INDEX "Subtask_completedById_idx" ON "Subtask"("completedById");

-- CreateIndex
CREATE INDEX "RequiredPart_taskId_idx" ON "RequiredPart"("taskId");

-- CreateIndex
CREATE INDEX "RequiredPart_partId_idx" ON "RequiredPart"("partId");

-- CreateIndex
CREATE INDEX "RequiredPart_issuedById_idx" ON "RequiredPart"("issuedById");

-- CreateIndex
CREATE INDEX "RequiredTool_taskId_idx" ON "RequiredTool"("taskId");

-- CreateIndex
CREATE INDEX "RequiredTool_toolId_idx" ON "RequiredTool"("toolId");

-- CreateIndex
CREATE INDEX "RequiredTool_checkedOutById_idx" ON "RequiredTool"("checkedOutById");

-- CreateIndex
CREATE INDEX "TaskAttachment_taskId_idx" ON "TaskAttachment"("taskId");

-- CreateIndex
CREATE INDEX "TaskAttachment_uploadedById_idx" ON "TaskAttachment"("uploadedById");

-- CreateIndex
CREATE INDEX "TaskSignoff_taskId_idx" ON "TaskSignoff"("taskId");

-- CreateIndex
CREATE INDEX "TaskSignoff_signedById_idx" ON "TaskSignoff"("signedById");

-- CreateIndex
CREATE INDEX "_StaffWorkOrders_B_index" ON "_StaffWorkOrders"("B");

-- CreateIndex
CREATE INDEX "_AssignedStaff_B_index" ON "_AssignedStaff"("B");

-- CreateIndex
CREATE INDEX "ComponentDocument_status_idx" ON "ComponentDocument"("status");

-- CreateIndex
CREATE INDEX "InventoryItem_partNumber_idx" ON "InventoryItem"("partNumber");

-- CreateIndex
CREATE INDEX "InventoryItem_serialNumber_idx" ON "InventoryItem"("serialNumber");

-- CreateIndex
CREATE INDEX "InventoryItem_category_idx" ON "InventoryItem"("category");

-- CreateIndex
CREATE INDEX "InventoryItem_status_idx" ON "InventoryItem"("status");

-- CreateIndex
CREATE INDEX "MaintenanceSchedule_aircraftId_idx" ON "MaintenanceSchedule"("aircraftId");

-- CreateIndex
CREATE INDEX "MaintenanceSchedule_createdById_idx" ON "MaintenanceSchedule"("createdById");

-- CreateIndex
CREATE INDEX "MaintenanceTask_workOrderId_idx" ON "MaintenanceTask"("workOrderId");

-- CreateIndex
CREATE INDEX "MaintenanceTask_supervisorId_idx" ON "MaintenanceTask"("supervisorId");

-- CreateIndex
CREATE INDEX "MaintenanceTask_assignedUserId_idx" ON "MaintenanceTask"("assignedUserId");

-- CreateIndex
CREATE INDEX "MaintenanceTask_createdById_idx" ON "MaintenanceTask"("createdById");

-- CreateIndex
CREATE INDEX "MaintenanceTask_updatedById_idx" ON "MaintenanceTask"("updatedById");

-- CreateIndex
CREATE INDEX "StockMovement_receiptId_idx" ON "StockMovement"("receiptId");

-- CreateIndex
CREATE INDEX "WorkOrder_scheduleId_idx" ON "WorkOrder"("scheduleId");

-- CreateIndex
CREATE INDEX "WorkOrder_aircraftId_idx" ON "WorkOrder"("aircraftId");

-- CreateIndex
CREATE INDEX "WorkOrderAttachment_workOrderId_idx" ON "WorkOrderAttachment"("workOrderId");

-- AddForeignKey
ALTER TABLE "StockMovement" ADD CONSTRAINT "StockMovement_receiptId_fkey" FOREIGN KEY ("receiptId") REFERENCES "Receipt"("id") ON DELETE SET NULL ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE "Subtask" ADD CONSTRAINT "Subtask_completedById_fkey" FOREIGN KEY ("completedById") REFERENCES "Staff"("id") ON DELETE SET NULL ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE "RequiredPart" ADD CONSTRAINT "RequiredPart_partId_fkey" FOREIGN KEY ("partId") REFERENCES "InventoryItem"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "RequiredPart" ADD CONSTRAINT "RequiredPart_issuedById_fkey" FOREIGN KEY ("issuedById") REFERENCES "Staff"("id") ON DELETE SET NULL ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE "RequiredTool" ADD CONSTRAINT "RequiredTool_toolId_fkey" FOREIGN KEY ("toolId") REFERENCES "Tool"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "RequiredTool" ADD CONSTRAINT "RequiredTool_checkedOutById_fkey" FOREIGN KEY ("checkedOutById") REFERENCES "Staff"("id") ON DELETE SET NULL ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE "TaskAttachment" ADD CONSTRAINT "TaskAttachment_uploadedById_fkey" FOREIGN KEY ("uploadedById") REFERENCES "Staff"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE "TaskSignoff" ADD CONSTRAINT "TaskSignoff_signedById_fkey" FOREIGN KEY ("signedById") REFERENCES "Staff"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MaintenanceSchedule" ADD CONSTRAINT "MaintenanceSchedule_aircraftId_fkey" FOREIGN KEY ("aircraftId") REFERENCES "Aircraft"("id") ON DELETE SET NULL ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE "WorkOrder" ADD CONSTRAINT "WorkOrder_scheduleId_fkey" FOREIGN KEY ("scheduleId") REFERENCES "MaintenanceSchedule"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "WorkOrder" ADD CONSTRAINT "WorkOrder_aircraftId_fkey" FOREIGN KEY ("aircraftId") REFERENCES "Aircraft"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MaintenanceTask" ADD CONSTRAINT "MaintenanceTask_workOrderId_fkey" FOREIGN KEY ("workOrderId") REFERENCES "WorkOrder"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MaintenanceTask" ADD CONSTRAINT "MaintenanceTask_supervisorId_fkey" FOREIGN KEY ("supervisorId") REFERENCES "Staff"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MaintenanceTask" ADD CONSTRAINT "MaintenanceTask_aircraftId_fkey" FOREIGN KEY ("aircraftId") REFERENCES "Aircraft"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MaintenanceTask" ADD CONSTRAINT "MaintenanceTask_assignedUserId_fkey" FOREIGN KEY ("assignedUserId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_StaffWorkOrders" ADD CONSTRAINT "_StaffWorkOrders_A_fkey" FOREIGN KEY ("A") REFERENCES "Staff"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_StaffWorkOrders" ADD CONSTRAINT "_StaffWorkOrders_B_fkey" FOREIGN KEY ("B") REFERENCES "WorkOrder"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_AssignedStaff" ADD CONSTRAINT "_AssignedStaff_A_fkey" FOREIGN KEY ("A") REFERENCES "MaintenanceTask"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_AssignedStaff" ADD CONSTRAINT "_AssignedStaff_B_fkey" FOREIGN KEY ("B") REFERENCES "Staff"("id") ON DELETE CASCADE ON UPDATE CASCADE;
