fix(backend/db): Keep CreditTransaction entries on User delete (#10917)

This is a non-critical improvement for bookkeeping purposes.

- Change `CreditTransaction` <- `User` relation to `ON DELETE NO ACTION`
so that `CreditTransactions` are not automatically deleted when we
delete a user's data.

- [x] I have clearly listed my changes in the PR description
- [x] I have made a test plan
- [x] I have tested my changes according to the test plan:
  - [x] Migration applies without problems
This commit is contained in:
Reinier van der Leer
2025-09-12 19:11:31 +02:00
parent e56a4a135d
commit fb8fbc9d1f
2 changed files with 4 additions and 1 deletions

View File

@@ -0,0 +1,3 @@
-- Re-create foreign key CreditTransaction <- User with ON DELETE NO ACTION
ALTER TABLE "CreditTransaction" DROP CONSTRAINT "CreditTransaction_userId_fkey";
ALTER TABLE "CreditTransaction" ADD CONSTRAINT "CreditTransaction_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE NO ACTION ON UPDATE CASCADE;

View File

@@ -528,7 +528,7 @@ model CreditTransaction {
createdAt DateTime @default(now())
userId String
User User @relation(fields: [userId], references: [id], onDelete: Cascade)
User User? @relation(fields: [userId], references: [id], onDelete: NoAction)
amount Int
type CreditTransactionType