From a61bd8c83ed9a4f92efeb92110a7f6423231a807 Mon Sep 17 00:00:00 2001 From: Kanjana Date: Wed, 9 Jul 2025 15:21:00 +0700 Subject: [PATCH] chore: migration --- .../migration.sql | 36 +++++++++++++++++++ prisma/schema.prisma | 32 +++++++++++++---- 2 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 prisma/migrations/20250709082027_add_business_type_add_delect_customer_name/migration.sql diff --git a/prisma/migrations/20250709082027_add_business_type_add_delect_customer_name/migration.sql b/prisma/migrations/20250709082027_add_business_type_add_delect_customer_name/migration.sql new file mode 100644 index 0000000..50f8cd1 --- /dev/null +++ b/prisma/migrations/20250709082027_add_business_type_add_delect_customer_name/migration.sql @@ -0,0 +1,36 @@ +/* + Warnings: + + - You are about to drop the column `businessType` on the `CustomerBranch` table. All the data in the column will be lost. + - You are about to drop the column `customerName` on the `CustomerBranch` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE "CustomerBranch" DROP COLUMN "businessType", +DROP COLUMN "customerName", +ADD COLUMN "businessTypeId" TEXT; + +-- AlterTable +ALTER TABLE "EmployeeVisa" ADD COLUMN "reportDate" DATE; + +-- CreateTable +CREATE TABLE "BusinessType" ( + "id" TEXT NOT NULL, + "name" TEXT NOT NULL, + "nameEN" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdByUserId" TEXT, + "updatedAt" TIMESTAMP(3) NOT NULL, + "updatedByUserId" TEXT, + + CONSTRAINT "BusinessType_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "CustomerBranch" ADD CONSTRAINT "CustomerBranch_businessTypeId_fkey" FOREIGN KEY ("businessTypeId") REFERENCES "BusinessType"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "BusinessType" ADD CONSTRAINT "BusinessType_createdByUserId_fkey" FOREIGN KEY ("createdByUserId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "BusinessType" ADD CONSTRAINT "BusinessType_updatedByUserId_fkey" FOREIGN KEY ("updatedByUserId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 72b19a3..e444ae1 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -501,6 +501,8 @@ model User { creditNoteCreated CreditNote[] @relation("CreditNoteCreatedByUser") institutionCreated Institution[] @relation("InstitutionCreatedByUser") institutionUpdated Institution[] @relation("InstitutionUpdatedByUser") + businessTypeCreated BusinessType[] @relation("BusinessTypeCreatedByUser") + businessTypeUpdated BusinessType[] @relation("BusinessTypeUpdatedByUser") requestWorkStepStatus RequestWorkStepStatus[] userTask UserTask[] @@ -550,10 +552,9 @@ model Customer { } model CustomerBranch { - id String @id @default(cuid()) - customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade) - customerId String - customerName String? + id String @id @default(cuid()) + customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade) + customerId String code String codeCustomer String @@ -615,7 +616,8 @@ model CustomerBranch { agentUser User? @relation(fields: [agentUserId], references: [id], onDelete: SetNull) // NOTE: Business - businessType String + businessTypeId String? + businessType BusinessType? @relation(fields: [businessTypeId], references: [id], onDelete: SetNull) jobPosition String jobDescription String payDate String @@ -774,6 +776,21 @@ model CustomerBranchVatRegis { customerBranch CustomerBranch @relation(fields: [customerBranchId], references: [id], onDelete: Cascade) } +model BusinessType { + id String @id @default(cuid()) + name String + nameEN String + + createdAt DateTime @default(now()) + createdBy User? @relation(name: "BusinessTypeCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull) + createdByUserId String? + updatedAt DateTime @updatedAt + updatedBy User? @relation(name: "BusinessTypeUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull) + updatedByUserId String? + + customerBranch CustomerBranch[] +} + model Employee { id String @id @default(cuid()) @@ -895,8 +912,9 @@ model EmployeeVisa { entryCount Int issueCountry String issuePlace String - issueDate DateTime @db.Date - expireDate DateTime @db.Date + issueDate DateTime @db.Date + expireDate DateTime @db.Date + reportDate DateTime? @db.Date mrz String? remark String?