From f3f27e8f8749e5eeb6951ffe7d8b9c381bef5814 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 10 Dec 2024 10:04:02 +0700 Subject: [PATCH] chore: migration --- .../migration.sql | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 prisma/migrations/20241210030230_update_task_relation/migration.sql diff --git a/prisma/migrations/20241210030230_update_task_relation/migration.sql b/prisma/migrations/20241210030230_update_task_relation/migration.sql new file mode 100644 index 0000000..64f531f --- /dev/null +++ b/prisma/migrations/20241210030230_update_task_relation/migration.sql @@ -0,0 +1,51 @@ +/* + Warnings: + + - The values [Redo] on the enum `RequestWorkStatus` will be removed. If these variants are still used in the database, this will fail. + - You are about to drop the column `taskOrderId` on the `RequestWorkStepStatus` table. All the data in the column will be lost. + - You are about to drop the column `taskStatus` on the `TaskOrder` table. All the data in the column will be lost. + +*/ +-- CreateEnum +CREATE TYPE "TaskOrderStatus" AS ENUM ('Pending', 'InProgress', 'Validate', 'Complete', 'Canceled'); + +-- AlterEnum +BEGIN; +CREATE TYPE "RequestWorkStatus_new" AS ENUM ('Pending', 'Ready', 'Waiting', 'InProgress', 'Validate', 'Ended', 'Completed', 'Canceled'); +ALTER TABLE "RequestWorkStepStatus" ALTER COLUMN "workStatus" DROP DEFAULT; +ALTER TABLE "RequestWorkStepStatus" ALTER COLUMN "workStatus" TYPE "RequestWorkStatus_new" USING ("workStatus"::text::"RequestWorkStatus_new"); +ALTER TYPE "RequestWorkStatus" RENAME TO "RequestWorkStatus_old"; +ALTER TYPE "RequestWorkStatus_new" RENAME TO "RequestWorkStatus"; +DROP TYPE "RequestWorkStatus_old"; +ALTER TABLE "RequestWorkStepStatus" ALTER COLUMN "workStatus" SET DEFAULT 'Pending'; +COMMIT; + +-- AlterEnum +ALTER TYPE "TaskStatus" ADD VALUE 'Redo'; + +-- DropForeignKey +ALTER TABLE "RequestWorkStepStatus" DROP CONSTRAINT "RequestWorkStepStatus_taskOrderId_fkey"; + +-- AlterTable +ALTER TABLE "RequestWorkStepStatus" DROP COLUMN "taskOrderId"; + +-- AlterTable +ALTER TABLE "TaskOrder" DROP COLUMN "taskStatus", +ADD COLUMN "taskOrderStatus" "TaskOrderStatus" NOT NULL DEFAULT 'Pending'; + +-- CreateTable +CREATE TABLE "Task" ( + "id" TEXT NOT NULL, + "taskStatus" "TaskStatus" NOT NULL DEFAULT 'Pending', + "step" INTEGER NOT NULL, + "requestWorkId" TEXT NOT NULL, + "taskOrderId" TEXT NOT NULL, + + CONSTRAINT "Task_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "Task" ADD CONSTRAINT "Task_step_requestWorkId_fkey" FOREIGN KEY ("step", "requestWorkId") REFERENCES "RequestWorkStepStatus"("step", "requestWorkId") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Task" ADD CONSTRAINT "Task_taskOrderId_fkey" FOREIGN KEY ("taskOrderId") REFERENCES "TaskOrder"("id") ON DELETE RESTRICT ON UPDATE CASCADE;