Cascades impersonations on user delete (#2891)

Co-authored-by: Alex van Andel <me@alexvanandel.com>
This commit is contained in:
Omar López 2022-05-26 09:48:02 -06:00 committed by GitHub
parent a0a4ff6ce6
commit 9710c6faa6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -0,0 +1,11 @@
-- DropForeignKey
ALTER TABLE "Impersonations" DROP CONSTRAINT "Impersonations_impersonatedById_fkey";
-- DropForeignKey
ALTER TABLE "Impersonations" DROP CONSTRAINT "Impersonations_impersonatedUserId_fkey";
-- AddForeignKey
ALTER TABLE "Impersonations" ADD CONSTRAINT "Impersonations_impersonatedUserId_fkey" FOREIGN KEY ("impersonatedUserId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Impersonations" ADD CONSTRAINT "Impersonations_impersonatedById_fkey" FOREIGN KEY ("impersonatedById") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -402,8 +402,8 @@ model Webhook {
model Impersonations {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
impersonatedUser User @relation("impersonated_user", fields: [impersonatedUserId], references: [id])
impersonatedBy User @relation("impersonated_by_user", fields: [impersonatedById], references: [id])
impersonatedUser User @relation("impersonated_user", fields: [impersonatedUserId], references: [id], onDelete: Cascade)
impersonatedBy User @relation("impersonated_by_user", fields: [impersonatedById], references: [id], onDelete: Cascade)
impersonatedUserId Int
impersonatedById Int
}