diff --git a/prisma/migrations/20240906041918_add_registered_branch_to_product_group/migration.sql b/prisma/migrations/20240906041918_add_registered_branch_to_product_group/migration.sql new file mode 100644 index 0000000..9b30583 --- /dev/null +++ b/prisma/migrations/20240906041918_add_registered_branch_to_product_group/migration.sql @@ -0,0 +1,20 @@ +/* + Warnings: + + - Made the column `customerBranchId` on table `Employee` required. This step will fail if there are existing NULL values in that column. + +*/ +-- DropForeignKey +ALTER TABLE "Employee" DROP CONSTRAINT "Employee_customerBranchId_fkey"; + +-- AlterTable +ALTER TABLE "Employee" ALTER COLUMN "customerBranchId" SET NOT NULL; + +-- AlterTable +ALTER TABLE "ProductGroup" ADD COLUMN "registeredBranchId" TEXT; + +-- AddForeignKey +ALTER TABLE "Employee" ADD CONSTRAINT "Employee_customerBranchId_fkey" FOREIGN KEY ("customerBranchId") REFERENCES "CustomerBranch"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "ProductGroup" ADD CONSTRAINT "ProductGroup_registeredBranchId_fkey" FOREIGN KEY ("registeredBranchId") REFERENCES "Branch"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index dcbf8a2..10a9395 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -239,6 +239,7 @@ model Branch { productRegistration Product[] serviceRegistration Service[] customerRegistration Customer[] + ProductGroup ProductGroup[] } model BranchBank { @@ -533,8 +534,8 @@ model Employee { entryDate DateTime? @db.Date workerStatus String? - customerBranch CustomerBranch? @relation(fields: [customerBranchId], references: [id], onDelete: SetNull) - customerBranchId String? + customerBranch CustomerBranch @relation(fields: [customerBranchId], references: [id], onDelete: Cascade) + customerBranchId String status Status @default(CREATED) statusOrder Int @default(0) @@ -657,6 +658,9 @@ model ProductGroup { status Status @default(CREATED) statusOrder Int @default(0) + registeredBranchId String? + registeredBranch Branch? @relation(fields: [registeredBranchId], references: [id]) + createdAt DateTime @default(now()) createdBy User? @relation(name: "ProductGroupCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull) createdByUserId String?