From 1baacf55dd876a3496006fea6b9d66ed5cd118da Mon Sep 17 00:00:00 2001 From: richard483 Date: Sat, 27 Jan 2024 16:56:49 +0700 Subject: [PATCH] updated schema --- package-lock.json | 4 +- package.json | 2 +- .../migration.sql | 41 +++++++++++++++++++ prisma/schema.prisma | 14 +++---- 4 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 prisma/migrations/20240127095615_applied_cascade_on_delete/migration.sql diff --git a/package-lock.json b/package-lock.json index 3aff2f9..c3b0a98 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "backend-8tech", - "version": "4.2.6", + "version": "4.2.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "backend-8tech", - "version": "4.2.6", + "version": "4.2.7", "license": "UNLICENSED", "dependencies": { "@nestjs/common": "^9.4.3", diff --git a/package.json b/package.json index 43e2161..5cdb26a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "backend-8tech", - "version": "4.2.6", + "version": "4.2.7", "description": "", "author": "8tech", "private": true, diff --git a/prisma/migrations/20240127095615_applied_cascade_on_delete/migration.sql b/prisma/migrations/20240127095615_applied_cascade_on_delete/migration.sql new file mode 100644 index 0000000..82542da --- /dev/null +++ b/prisma/migrations/20240127095615_applied_cascade_on_delete/migration.sql @@ -0,0 +1,41 @@ +-- DropForeignKey +ALTER TABLE "Contract" DROP CONSTRAINT "Contract_jobId_fkey"; + +-- DropForeignKey +ALTER TABLE "Contract" DROP CONSTRAINT "Contract_paymentId_fkey"; + +-- DropForeignKey +ALTER TABLE "Contract" DROP CONSTRAINT "Contract_ratingId_fkey"; + +-- DropForeignKey +ALTER TABLE "Contract" DROP CONSTRAINT "Contract_userId_fkey"; + +-- DropForeignKey +ALTER TABLE "JobVacancy" DROP CONSTRAINT "JobVacancy_companyId_fkey"; + +-- DropForeignKey +ALTER TABLE "Rating" DROP CONSTRAINT "Rating_userId_fkey"; + +-- DropForeignKey +ALTER TABLE "User" DROP CONSTRAINT "User_companyId_fkey"; + +-- AddForeignKey +ALTER TABLE "User" ADD CONSTRAINT "User_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "Company"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "JobVacancy" ADD CONSTRAINT "JobVacancy_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "Company"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Contract" ADD CONSTRAINT "Contract_jobId_fkey" FOREIGN KEY ("jobId") REFERENCES "JobVacancy"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Contract" ADD CONSTRAINT "Contract_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Contract" ADD CONSTRAINT "Contract_paymentId_fkey" FOREIGN KEY ("paymentId") REFERENCES "Payment"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Contract" ADD CONSTRAINT "Contract_ratingId_fkey" FOREIGN KEY ("ratingId") REFERENCES "Rating"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Rating" ADD CONSTRAINT "Rating_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index e4f5f53..f2a7646 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -32,7 +32,7 @@ model User { portfolio String[] @map("portfolio") profilePicture String? hasGoogleAccount Boolean @default(false) - company Company? @relation(fields: [companyId], references: [id]) + company Company? @relation(fields: [companyId], references: [id], onDelete: Cascade) contract Contract[] } @@ -43,7 +43,7 @@ model JobVacancy { createdAt DateTime @default(now()) updatedAt DateTime @updatedAt // company Id is optional for current development purposes - company Company? @relation(fields: [companyId], references: [id]) + company Company? @relation(fields: [companyId], references: [id], onDelete: Cascade) companyId String? contracts Contract[] } @@ -74,10 +74,10 @@ model Contract { customField String? workSubmission String? ratingId String? - jobVacancy JobVacancy? @relation(fields: [jobId], references: [id]) - user User? @relation(fields: [userId], references: [id]) - payment Payment? @relation(fields: [paymentId], references: [id]) - rating Rating? @relation(fields: [ratingId], references: [id]) + jobVacancy JobVacancy? @relation(fields: [jobId], references: [id], onDelete: Cascade) + user User? @relation(fields: [userId], references: [id], onDelete: Cascade) + payment Payment? @relation(fields: [paymentId], references: [id], onDelete: Cascade) + rating Rating? @relation(fields: [ratingId], references: [id], onDelete: Cascade) } model Payment { @@ -92,7 +92,7 @@ model Payment { model Rating { id String @id @default(uuid()) - User User @relation(fields: [userId], references: [id]) + User User @relation(fields: [userId], references: [id], onDelete: Cascade) userId String recruiterUserId String ratingOf10 Int