/*
  Warnings:

  - You are about to drop the column `status` on the `User` table. All the data in the column will be lost.

*/
-- DropIndex
DROP INDEX "User_role_idx";

-- DropIndex
DROP INDEX "User_status_idx";

-- AlterTable
ALTER TABLE "User" DROP COLUMN "status";

-- CreateTable
CREATE TABLE "AirworthinessDirective" (
    "id" TEXT NOT NULL,
    "adNumber" TEXT NOT NULL,
    "title" TEXT NOT NULL,
    "description" TEXT NOT NULL,
    "issueDate" TIMESTAMP(3) NOT NULL,
    "effectiveDate" TIMESTAMP(3) NOT NULL,
    "status" TEXT NOT NULL DEFAULT 'Draft',
    "applicability" TEXT NOT NULL,
    "compliance" TEXT NOT NULL,
    "references" TEXT[],
    "attachments" JSONB,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "createdById" TEXT NOT NULL,
    "updatedById" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "ServiceBulletin" (
    "id" TEXT NOT NULL,
    "sbNumber" TEXT NOT NULL,
    "title" TEXT NOT NULL,
    "description" TEXT NOT NULL,
    "issueDate" TIMESTAMP(3) NOT NULL,
    "category" TEXT NOT NULL,
    "manufacturer" TEXT NOT NULL,
    "applicability" TEXT NOT NULL,
    "compliance" TEXT NOT NULL,
    "manHours" TEXT NOT NULL,
    "materialRequired" TEXT[],
    "references" TEXT[],
    "attachments" JSONB,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "createdById" TEXT NOT NULL,
    "updatedById" TEXT NOT NULL,

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

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

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

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

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

-- CreateIndex
CREATE UNIQUE INDEX "AirworthinessDirective_adNumber_key" ON "AirworthinessDirective"("adNumber");

-- CreateIndex
CREATE INDEX "AirworthinessDirective_adNumber_idx" ON "AirworthinessDirective"("adNumber");

-- CreateIndex
CREATE INDEX "AirworthinessDirective_status_idx" ON "AirworthinessDirective"("status");

-- CreateIndex
CREATE INDEX "AirworthinessDirective_issueDate_idx" ON "AirworthinessDirective"("issueDate");

-- CreateIndex
CREATE UNIQUE INDEX "ServiceBulletin_sbNumber_key" ON "ServiceBulletin"("sbNumber");

-- CreateIndex
CREATE INDEX "ServiceBulletin_sbNumber_idx" ON "ServiceBulletin"("sbNumber");

-- CreateIndex
CREATE INDEX "ServiceBulletin_category_idx" ON "ServiceBulletin"("category");

-- CreateIndex
CREATE INDEX "ServiceBulletin_issueDate_idx" ON "ServiceBulletin"("issueDate");

-- CreateIndex
CREATE INDEX "ServiceBulletin_manufacturer_idx" ON "ServiceBulletin"("manufacturer");

-- CreateIndex
CREATE INDEX "_AircraftToAirworthinessDirective_B_index" ON "_AircraftToAirworthinessDirective"("B");

-- CreateIndex
CREATE INDEX "_AircraftToServiceBulletin_B_index" ON "_AircraftToServiceBulletin"("B");

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

-- AddForeignKey
ALTER TABLE "AirworthinessDirective" ADD CONSTRAINT "AirworthinessDirective_updatedById_fkey" FOREIGN KEY ("updatedById") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE "ServiceBulletin" ADD CONSTRAINT "ServiceBulletin_updatedById_fkey" FOREIGN KEY ("updatedById") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_AircraftToAirworthinessDirective" ADD CONSTRAINT "_AircraftToAirworthinessDirective_A_fkey" FOREIGN KEY ("A") REFERENCES "Aircraft"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_AircraftToAirworthinessDirective" ADD CONSTRAINT "_AircraftToAirworthinessDirective_B_fkey" FOREIGN KEY ("B") REFERENCES "AirworthinessDirective"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_AircraftToServiceBulletin" ADD CONSTRAINT "_AircraftToServiceBulletin_A_fkey" FOREIGN KEY ("A") REFERENCES "Aircraft"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_AircraftToServiceBulletin" ADD CONSTRAINT "_AircraftToServiceBulletin_B_fkey" FOREIGN KEY ("B") REFERENCES "ServiceBulletin"("id") ON DELETE CASCADE ON UPDATE CASCADE;
