文件
hyb-oa/server/prisma/migrations/20260329203000_r45_employee_training_certificates/migration.sql
T

60 行
2.1 KiB
SQL

-- CreateEnum
CREATE TYPE "EmployeeTrainingType" AS ENUM ('internal', 'external', 'online');
-- CreateEnum
CREATE TYPE "EmployeeTrainingStatus" AS ENUM ('planned', 'in_progress', 'completed', 'cancelled');
-- CreateTable
CREATE TABLE "employee_trainings" (
"id" UUID NOT NULL,
"employee_id" UUID NOT NULL,
"name" TEXT NOT NULL,
"training_type" "EmployeeTrainingType" NOT NULL,
"start_date" DATE NOT NULL,
"end_date" DATE,
"status" "EmployeeTrainingStatus" NOT NULL,
"notes" TEXT,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"created_by" UUID,
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_by" UUID,
CONSTRAINT "employee_trainings_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "employee_certificates" (
"id" UUID NOT NULL,
"employee_id" UUID NOT NULL,
"name" TEXT NOT NULL,
"issuer" TEXT NOT NULL,
"obtained_date" DATE NOT NULL,
"expiry_date" DATE,
"certificate_no" TEXT,
"attachment_path" TEXT,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"created_by" UUID,
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_by" UUID,
CONSTRAINT "employee_certificates_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "idx_employee_trainings_employee_start" ON "employee_trainings"("employee_id", "start_date");
-- CreateIndex
CREATE INDEX "idx_employee_trainings_employee_status" ON "employee_trainings"("employee_id", "status");
-- CreateIndex
CREATE INDEX "idx_employee_certificates_employee_obtained" ON "employee_certificates"("employee_id", "obtained_date");
-- CreateIndex
CREATE INDEX "idx_employee_certificates_employee_expiry" ON "employee_certificates"("employee_id", "expiry_date");
-- AddForeignKey
ALTER TABLE "employee_trainings" ADD CONSTRAINT "employee_trainings_employee_id_fkey" FOREIGN KEY ("employee_id") REFERENCES "employees"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "employee_certificates" ADD CONSTRAINT "employee_certificates_employee_id_fkey" FOREIGN KEY ("employee_id") REFERENCES "employees"("id") ON DELETE CASCADE ON UPDATE CASCADE;