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