From 31ed48d190675aa810db6ac3df478735cd2961b5 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 12 Jun 2024 14:09:08 +0700 Subject: [PATCH] chore: update migration --- .../migration.sql | 36 ++++++++++++++++ .../migration.sql | 8 ++++ .../migration.sql | 18 ++++++++ prisma/schema.prisma | 42 +++++++++++++------ 4 files changed, 91 insertions(+), 13 deletions(-) create mode 100644 prisma/migrations/20240612042722_overhaul_service_table/migration.sql create mode 100644 prisma/migrations/20240612045512_remove_order_from_work/migration.sql create mode 100644 prisma/migrations/20240612065711_composite_key_m2m/migration.sql diff --git a/prisma/migrations/20240612042722_overhaul_service_table/migration.sql b/prisma/migrations/20240612042722_overhaul_service_table/migration.sql new file mode 100644 index 0000000..3549d90 --- /dev/null +++ b/prisma/migrations/20240612042722_overhaul_service_table/migration.sql @@ -0,0 +1,36 @@ +/* + Warnings: + + - You are about to drop the column `serviceId` on the `Work` table. All the data in the column will be lost. + - Added the required column `order` to the `WorkProduct` table without a default value. This is not possible if the table is not empty. + +*/ +-- DropForeignKey +ALTER TABLE "Work" DROP CONSTRAINT "Work_serviceId_fkey"; + +-- AlterTable +ALTER TABLE "Work" DROP COLUMN "serviceId"; + +-- AlterTable +ALTER TABLE "WorkProduct" ADD COLUMN "order" INTEGER NOT NULL; + +-- CreateTable +CREATE TABLE "WorkService" ( + "id" TEXT NOT NULL, + "order" INTEGER NOT NULL, + "workId" TEXT NOT NULL, + "serviceId" TEXT NOT NULL, + "createdBy" TEXT, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updateBy" TEXT, + "updatedAt" TIMESTAMP(3) NOT NULL, + "productId" TEXT, + + CONSTRAINT "WorkService_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "WorkService" ADD CONSTRAINT "WorkService_workId_fkey" FOREIGN KEY ("workId") REFERENCES "Work"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "WorkService" ADD CONSTRAINT "WorkService_serviceId_fkey" FOREIGN KEY ("serviceId") REFERENCES "Service"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20240612045512_remove_order_from_work/migration.sql b/prisma/migrations/20240612045512_remove_order_from_work/migration.sql new file mode 100644 index 0000000..7255159 --- /dev/null +++ b/prisma/migrations/20240612045512_remove_order_from_work/migration.sql @@ -0,0 +1,8 @@ +/* + Warnings: + + - You are about to drop the column `order` on the `Work` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE "Work" DROP COLUMN "order"; diff --git a/prisma/migrations/20240612065711_composite_key_m2m/migration.sql b/prisma/migrations/20240612065711_composite_key_m2m/migration.sql new file mode 100644 index 0000000..027089e --- /dev/null +++ b/prisma/migrations/20240612065711_composite_key_m2m/migration.sql @@ -0,0 +1,18 @@ +/* + Warnings: + + - The primary key for the `WorkProduct` table will be changed. If it partially fails, the table could be left without primary key constraint. + - You are about to drop the column `id` on the `WorkProduct` table. All the data in the column will be lost. + - The primary key for the `WorkService` table will be changed. If it partially fails, the table could be left without primary key constraint. + - You are about to drop the column `id` on the `WorkService` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE "WorkProduct" DROP CONSTRAINT "WorkProduct_pkey", +DROP COLUMN "id", +ADD CONSTRAINT "WorkProduct_pkey" PRIMARY KEY ("workId", "productId"); + +-- AlterTable +ALTER TABLE "WorkService" DROP CONSTRAINT "WorkService_pkey", +DROP COLUMN "id", +ADD CONSTRAINT "WorkService_pkey" PRIMARY KEY ("workId", "serviceId"); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 432e0e6..1f67779 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -547,30 +547,44 @@ model Service { createdAt DateTime @default(now()) updateBy String? updatedAt DateTime @updatedAt - work Work[] + + workOnService WorkService[] } model Work { id String @id @default(uuid()) - order Int - name String - - service Service @relation(fields: [serviceId], references: [id], onDelete: Cascade) - serviceId String + name String status Status @default(CREATED) - createdBy String? - createdAt DateTime @default(now()) - updateBy String? - updatedAt DateTime @updatedAt - WorkProduct WorkProduct[] + createdBy String? + createdAt DateTime @default(now()) + updateBy String? + updatedAt DateTime @updatedAt + + productOnWork WorkProduct[] + serviceOnWork WorkService[] +} + +model WorkService { + order Int + work Work @relation(fields: [workId], references: [id], onDelete: Cascade) + workId String + service Service @relation(fields: [serviceId], references: [id], onDelete: Cascade) + serviceId String + + createdBy String? + createdAt DateTime @default(now()) + updateBy String? + updatedAt DateTime @updatedAt + productId String? + + @@id([workId, serviceId]) } model WorkProduct { - id String @id @default(uuid()) - + order Int work Work @relation(fields: [workId], references: [id], onDelete: Cascade) workId String product Product @relation(fields: [productId], references: [id], onDelete: Cascade) @@ -580,6 +594,8 @@ model WorkProduct { createdAt DateTime @default(now()) updateBy String? updatedAt DateTime @updatedAt + + @@id([workId, productId]) } model ProductGroup {