/*
  Warnings:

  - You are about to drop the column `tingkat` on the `cp_fase` table. All the data in the column will be lost.
  - A unique constraint covering the columns `[tahunPelajaran,semester,rombelId,guruId,mapelId]` on the table `cp_fase` will be added. If there are existing duplicate values, this will fail.
  - Added the required column `rombelId` to the `cp_fase` table without a default value. This is not possible if the table is not empty.

*/
-- DropIndex
DROP INDEX "cp_fase_tahunPelajaran_semester_tingkat_guruId_mapelId_key";

-- AlterTable
ALTER TABLE "cp_fase" DROP COLUMN "tingkat",
ADD COLUMN     "rombelId" TEXT NOT NULL;

-- DropEnum
DROP TYPE "Tingkat";

-- CreateTable
CREATE TABLE "rombel" (
    "id" TEXT NOT NULL,
    "namaRombel" TEXT NOT NULL,
    "tingkat" TEXT NOT NULL,
    "tahunPelajaran" TEXT NOT NULL,
    "jurusanId" TEXT,
    "waliKelasId" TEXT,
    "isActive" BOOLEAN NOT NULL DEFAULT true,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "rombel_namaRombel_tahunPelajaran_key" ON "rombel"("namaRombel", "tahunPelajaran");

-- CreateIndex
CREATE UNIQUE INDEX "cp_fase_tahunPelajaran_semester_rombelId_guruId_mapelId_key" ON "cp_fase"("tahunPelajaran", "semester", "rombelId", "guruId", "mapelId");

-- AddForeignKey
ALTER TABLE "rombel" ADD CONSTRAINT "rombel_jurusanId_fkey" FOREIGN KEY ("jurusanId") REFERENCES "jurusan"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "cp_fase" ADD CONSTRAINT "cp_fase_rombelId_fkey" FOREIGN KEY ("rombelId") REFERENCES "rombel"("id") ON DELETE CASCADE ON UPDATE CASCADE;
