-- CreateEnum
CREATE TYPE "RoutineExceptionType" AS ENUM ('CANCELLED', 'RESCHEDULED');

-- 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 "SubmissionStatus" ADD VALUE 'LATE_SUBMITTED';
ALTER TYPE "SubmissionStatus" ADD VALUE 'UNDER_REVIEW';
ALTER TYPE "SubmissionStatus" ADD VALUE 'RETURNED_FOR_REVISION';

-- AlterTable
ALTER TABLE "exams" ADD COLUMN     "venue" VARCHAR(120);

-- AlterTable
ALTER TABLE "notices" ADD COLUMN     "attachmentFilename" VARCHAR(255),
ADD COLUMN     "attachmentMimeType" VARCHAR(120),
ADD COLUMN     "attachmentObjectKey" VARCHAR(512),
ADD COLUMN     "attachmentSizeBytes" INTEGER;

-- CreateTable
CREATE TABLE "routine_exceptions" (
    "id" UUID NOT NULL,
    "routineEntryId" UUID NOT NULL,
    "exceptionDate" DATE NOT NULL,
    "type" "RoutineExceptionType" NOT NULL,
    "reason" VARCHAR(255),
    "overrideStartTime" VARCHAR(5),
    "overrideEndTime" VARCHAR(5),
    "overrideStartMinute" INTEGER,
    "overrideEndMinute" INTEGER,
    "overrideRoom" VARCHAR(64),
    "createdById" UUID,
    "createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMPTZ(3) NOT NULL,

    CONSTRAINT "routine_exceptions_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE INDEX "routine_exceptions_exceptionDate_type_idx" ON "routine_exceptions"("exceptionDate", "type");

-- CreateIndex
CREATE UNIQUE INDEX "routine_exceptions_routineEntryId_exceptionDate_key" ON "routine_exceptions"("routineEntryId", "exceptionDate");

-- AddForeignKey
ALTER TABLE "routine_exceptions" ADD CONSTRAINT "routine_exceptions_routineEntryId_fkey" FOREIGN KEY ("routineEntryId") REFERENCES "routine_entries"("id") ON DELETE CASCADE ON UPDATE CASCADE;
