Skip to content

Commit

Permalink
feat(api): cascading user relations (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkdev98 authored Aug 22, 2024
1 parent 7b7ceee commit 773ad4d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- DropForeignKey
ALTER TABLE "BudgetUserInvitation" DROP CONSTRAINT "BudgetUserInvitation_createdByUserId_fkey";

-- DropForeignKey
ALTER TABLE "UserWalletAccount" DROP CONSTRAINT "UserWalletAccount_userId_fkey";

-- AddForeignKey
ALTER TABLE "UserWalletAccount" ADD CONSTRAINT "UserWalletAccount_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "BudgetUserInvitation" ADD CONSTRAINT "BudgetUserInvitation_createdByUserId_fkey" FOREIGN KEY ("createdByUserId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
6 changes: 3 additions & 3 deletions apps/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ model UserWalletAccount {
preferredCurrency String
userId String
user User @relation(fields: [userId], references: [id])
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
transactions Transaction[]
}

Expand Down Expand Up @@ -125,7 +125,7 @@ model BudgetUserInvitation {
permission BudgetUserPermission?
createdByUserId String
createdByUser User @relation(fields: [createdByUserId], references: [id])
createdByUser User @relation(fields: [createdByUserId], references: [id], onDelete: Cascade)
budgetId String
budget Budget @relation(fields: [budgetId], references: [id], onDelete: Cascade)
responses BudgetUserInvitationResponse[]
Expand All @@ -145,7 +145,7 @@ model BudgetUserInvitationResponse {
invitationId String
invitation BudgetUserInvitation @relation(fields: [invitationId], references: [id])
createdUserId String? @unique
createdUser User? @relation(fields: [createdUserId], references: [id])
createdUser User? @relation(fields: [createdUserId], references: [id], onDelete: SetNull)
}

model Transaction {
Expand Down

0 comments on commit 773ad4d

Please sign in to comment.