Skip to content

Commit

Permalink
fix: Error on existing booking when credential is deleted (#16784)
Browse files Browse the repository at this point in the history
  • Loading branch information
emrysal authored Sep 24, 2024
1 parent f6ba77c commit 04a0e46
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- DropIndex
DROP INDEX "BookingReference_credentialId_idx";

-- Remove disconnected Credentials from bookingReference to prevent foreign key constraint error
UPDATE "BookingReference"
SET "credentialId" = NULL
WHERE "credentialId" IS NOT NULL
AND "credentialId" NOT IN (SELECT "id" FROM "Credential");

-- AddForeignKey
ALTER TABLE "BookingReference" ADD CONSTRAINT "BookingReference_credentialId_fkey" FOREIGN KEY ("credentialId") REFERENCES "Credential"("id") ON DELETE SET NULL ON UPDATE CASCADE;
6 changes: 4 additions & 2 deletions packages/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ model Credential {
selectedCalendars SelectedCalendar[]
invalid Boolean? @default(false)
CalendarCache CalendarCache[]
references BookingReference[]
@@index([userId])
@@index([appId])
Expand Down Expand Up @@ -533,10 +534,11 @@ model BookingReference {
bookingId Int?
externalCalendarId String?
deleted Boolean?
credentialId Int?
credential Credential? @relation(fields: [credentialId], references: [id], onDelete: SetNull)
credentialId Int?
@@index([bookingId])
@@index([credentialId])
@@index([type])
@@index([uid])
}
Expand Down

0 comments on commit 04a0e46

Please sign in to comment.