From b48172e33715a398fe431796f28ad8e63ff88bdf Mon Sep 17 00:00:00 2001 From: CactusBlue Date: Tue, 25 Feb 2025 12:14:01 -0800 Subject: [PATCH] Add cascade to sentEmail (#463) * add delete cascade * add cascade to both --- .../20250225200753_add_tenancy_cascade/migration.sql | 5 +++++ .../migrations/20250225200857_add_another/migration.sql | 5 +++++ apps/backend/prisma/schema.prisma | 4 ++-- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 apps/backend/prisma/migrations/20250225200753_add_tenancy_cascade/migration.sql create mode 100644 apps/backend/prisma/migrations/20250225200857_add_another/migration.sql diff --git a/apps/backend/prisma/migrations/20250225200753_add_tenancy_cascade/migration.sql b/apps/backend/prisma/migrations/20250225200753_add_tenancy_cascade/migration.sql new file mode 100644 index 000000000..9bd2e426e --- /dev/null +++ b/apps/backend/prisma/migrations/20250225200753_add_tenancy_cascade/migration.sql @@ -0,0 +1,5 @@ +-- DropForeignKey +ALTER TABLE "SentEmail" DROP CONSTRAINT "SentEmail_tenancyId_fkey"; + +-- AddForeignKey +ALTER TABLE "SentEmail" ADD CONSTRAINT "SentEmail_tenancyId_fkey" FOREIGN KEY ("tenancyId") REFERENCES "Tenancy"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/apps/backend/prisma/migrations/20250225200857_add_another/migration.sql b/apps/backend/prisma/migrations/20250225200857_add_another/migration.sql new file mode 100644 index 000000000..cfc5de63d --- /dev/null +++ b/apps/backend/prisma/migrations/20250225200857_add_another/migration.sql @@ -0,0 +1,5 @@ +-- DropForeignKey +ALTER TABLE "SentEmail" DROP CONSTRAINT "SentEmail_tenancyId_userId_fkey"; + +-- AddForeignKey +ALTER TABLE "SentEmail" ADD CONSTRAINT "SentEmail_tenancyId_userId_fkey" FOREIGN KEY ("tenancyId", "userId") REFERENCES "ProjectUser"("tenancyId", "projectUserId") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/apps/backend/prisma/schema.prisma b/apps/backend/prisma/schema.prisma index 1d17d4dc1..5707871eb 100644 --- a/apps/backend/prisma/schema.prisma +++ b/apps/backend/prisma/schema.prisma @@ -944,8 +944,8 @@ model SentEmail { text String? error Json? - tenancy Tenancy @relation(fields: [tenancyId], references: [id]) - user ProjectUser? @relation(fields: [tenancyId, userId], references: [tenancyId, projectUserId]) + tenancy Tenancy @relation(fields: [tenancyId], references: [id], onDelete: Cascade) + user ProjectUser? @relation(fields: [tenancyId, userId], references: [tenancyId, projectUserId], onDelete: Cascade) @@id([tenancyId, id]) }