文件
hyb-oa/server/prisma/migrations/20260329230000_r46_performance_reviews/migration.sql
T

89 行
3.6 KiB
SQL

-- CreateEnum
CREATE TYPE "PerformanceReviewCycleType" AS ENUM ('monthly', 'quarterly', 'semi_annual', 'annual');
-- CreateEnum
CREATE TYPE "PerformanceReviewCycleStatus" AS ENUM ('draft', 'active', 'completed');
-- CreateEnum
CREATE TYPE "PerformanceReviewDimensionType" AS ENUM ('work_quality', 'work_efficiency', 'teamwork', 'initiative', 'professional_skill');
-- CreateTable
CREATE TABLE "performance_review_cycles" (
"id" UUID NOT NULL,
"name" TEXT NOT NULL,
"cycle_type" "PerformanceReviewCycleType" NOT NULL,
"start_date" DATE NOT NULL,
"end_date" DATE NOT NULL,
"status" "PerformanceReviewCycleStatus" NOT NULL DEFAULT 'draft',
"activated_at" TIMESTAMP(3),
"completed_at" TIMESTAMP(3),
"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 "performance_review_cycles_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "performance_reviews" (
"id" UUID NOT NULL,
"cycle_id" UUID NOT NULL,
"employee_id" UUID NOT NULL,
"reviewer_employee_id" UUID NOT NULL,
"overall_score" DECIMAL(3,1) NOT NULL,
"comment" 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 "performance_reviews_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "performance_review_dimensions" (
"id" UUID NOT NULL,
"review_id" UUID NOT NULL,
"dimension_type" "PerformanceReviewDimensionType" NOT NULL,
"score" DECIMAL(3,1) NOT NULL,
CONSTRAINT "performance_review_dimensions_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "idx_performance_review_cycles_status_start" ON "performance_review_cycles"("status", "start_date");
-- CreateIndex
CREATE INDEX "idx_performance_review_cycles_status_completed" ON "performance_review_cycles"("status", "completed_at");
-- CreateIndex
CREATE UNIQUE INDEX "performance_review_cycles_single_active_ux" ON "performance_review_cycles"("status") WHERE "status" = 'active';
-- CreateIndex
CREATE UNIQUE INDEX "performance_reviews_cycle_employee_ux" ON "performance_reviews"("cycle_id", "employee_id");
-- CreateIndex
CREATE INDEX "idx_performance_reviews_cycle_reviewer" ON "performance_reviews"("cycle_id", "reviewer_employee_id");
-- CreateIndex
CREATE INDEX "idx_performance_reviews_employee_created" ON "performance_reviews"("employee_id", "created_at");
-- CreateIndex
CREATE UNIQUE INDEX "performance_review_dimensions_review_dimension_ux" ON "performance_review_dimensions"("review_id", "dimension_type");
-- CreateIndex
CREATE INDEX "idx_performance_review_dimensions_dimension_score" ON "performance_review_dimensions"("dimension_type", "score");
-- AddForeignKey
ALTER TABLE "performance_reviews" ADD CONSTRAINT "performance_reviews_cycle_id_fkey" FOREIGN KEY ("cycle_id") REFERENCES "performance_review_cycles"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "performance_reviews" ADD CONSTRAINT "performance_reviews_employee_id_fkey" FOREIGN KEY ("employee_id") REFERENCES "employees"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "performance_reviews" ADD CONSTRAINT "performance_reviews_reviewer_employee_id_fkey" FOREIGN KEY ("reviewer_employee_id") REFERENCES "employees"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "performance_review_dimensions" ADD CONSTRAINT "performance_review_dimensions_review_id_fkey" FOREIGN KEY ("review_id") REFERENCES "performance_reviews"("id") ON DELETE CASCADE ON UPDATE CASCADE;