From 5e943047e29c0861cc8a8c44bf121448d0a5461e Mon Sep 17 00:00:00 2001 From: Bryann Yeap Kok Keong Date: Fri, 4 Nov 2022 16:48:15 +0800 Subject: [PATCH] [offers][fix] Fix bug where offers are unable to be deleted due to being referenced by analysisUnit --- .../migration.sql | 5 +++++ .../migration.sql | 5 +++++ apps/portal/prisma/schema.prisma | 4 ++-- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 apps/portal/prisma/migrations/20221104084342_add_cascade_delete_to_analysed_offer_in_analysis_unit/migration.sql create mode 100644 apps/portal/prisma/migrations/20221104084451_add_cascade_delete_to_overall_analysis_in_offers_analysis/migration.sql diff --git a/apps/portal/prisma/migrations/20221104084342_add_cascade_delete_to_analysed_offer_in_analysis_unit/migration.sql b/apps/portal/prisma/migrations/20221104084342_add_cascade_delete_to_analysed_offer_in_analysis_unit/migration.sql new file mode 100644 index 00000000..12ec892c --- /dev/null +++ b/apps/portal/prisma/migrations/20221104084342_add_cascade_delete_to_analysed_offer_in_analysis_unit/migration.sql @@ -0,0 +1,5 @@ +-- DropForeignKey +ALTER TABLE "OffersAnalysisUnit" DROP CONSTRAINT "OffersAnalysisUnit_analysedOfferId_fkey"; + +-- AddForeignKey +ALTER TABLE "OffersAnalysisUnit" ADD CONSTRAINT "OffersAnalysisUnit_analysedOfferId_fkey" FOREIGN KEY ("analysedOfferId") REFERENCES "OffersOffer"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/apps/portal/prisma/migrations/20221104084451_add_cascade_delete_to_overall_analysis_in_offers_analysis/migration.sql b/apps/portal/prisma/migrations/20221104084451_add_cascade_delete_to_overall_analysis_in_offers_analysis/migration.sql new file mode 100644 index 00000000..a04f6969 --- /dev/null +++ b/apps/portal/prisma/migrations/20221104084451_add_cascade_delete_to_overall_analysis_in_offers_analysis/migration.sql @@ -0,0 +1,5 @@ +-- DropForeignKey +ALTER TABLE "OffersAnalysis" DROP CONSTRAINT "OffersAnalysis_overallAnalysisUnitId_fkey"; + +-- AddForeignKey +ALTER TABLE "OffersAnalysis" ADD CONSTRAINT "OffersAnalysis_overallAnalysisUnitId_fkey" FOREIGN KEY ("overallAnalysisUnitId") REFERENCES "OffersAnalysisUnit"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/apps/portal/prisma/schema.prisma b/apps/portal/prisma/schema.prisma index ca3806c1..662a321c 100644 --- a/apps/portal/prisma/schema.prisma +++ b/apps/portal/prisma/schema.prisma @@ -410,7 +410,7 @@ model OffersAnalysis { offerId String @unique // OVERALL - overallAnalysis OffersAnalysisUnit @relation("OverallAnalysis", fields: [overallAnalysisUnitId], references: [id]) + overallAnalysis OffersAnalysisUnit @relation("OverallAnalysis", fields: [overallAnalysisUnitId], references: [id], onDelete: Cascade) overallAnalysisUnitId String companyAnalysis OffersAnalysisUnit[] @relation("CompanyAnalysis") @@ -419,7 +419,7 @@ model OffersAnalysis { model OffersAnalysisUnit { id String @id @default(cuid()) - analysedOffer OffersOffer @relation("Analysed Offer", fields: [analysedOfferId], references: [id]) + analysedOffer OffersOffer @relation("Analysed Offer", fields: [analysedOfferId], references: [id], onDelete: Cascade) analysedOfferId String percentile Float