-- CreateEnum
CREATE TYPE "AppraisalStatus" AS ENUM ('DRAFT', 'SUBMITTED', 'MPO_VERIFIED', 'MANAGER_APPROVED', 'REJECTED');

-- AlterEnum
-- This migration adds more than one value to an enum.
-- With PostgreSQL versions 11 and earlier, this is not possible
-- in a single migration. This can be worked around by creating
-- multiple migrations, each migration adding only one value to
-- the enum.


ALTER TYPE "CrewActionType" ADD VALUE 'APPRAISAL_SUBMITTED';
ALTER TYPE "CrewActionType" ADD VALUE 'APPRAISAL_VERIFIED';
ALTER TYPE "CrewActionType" ADD VALUE 'APPRAISAL_APPROVED';
ALTER TYPE "CrewActionType" ADD VALUE 'APPRAISAL_REJECTED';

-- CreateTable
CREATE TABLE "Appraisal" (
    "id" TEXT NOT NULL,
    "assignmentId" TEXT NOT NULL,
    "period" TEXT NOT NULL,
    "ratings" JSONB,
    "comments" TEXT,
    "status" "AppraisalStatus" NOT NULL DEFAULT 'SUBMITTED',
    "rejectedReason" TEXT,
    "addedById" TEXT NOT NULL,
    "verifiedById" TEXT,
    "approvedById" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- AddForeignKey
ALTER TABLE "Appraisal" ADD CONSTRAINT "Appraisal_assignmentId_fkey" FOREIGN KEY ("assignmentId") REFERENCES "CrewAssignment"("id") ON DELETE CASCADE ON UPDATE CASCADE;
