From b57092ce3ee1806922c9a1e1959d66d752b70067 Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Thu, 13 Oct 2022 23:26:56 +0200 Subject: [PATCH] fix: delete share if user deleted --- .../migration.sql | 14 ++++++++++++++ backend/prisma/schema.prisma | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 backend/prisma/migrations/20221013212615_cascade_delete_on_share/migration.sql diff --git a/backend/prisma/migrations/20221013212615_cascade_delete_on_share/migration.sql b/backend/prisma/migrations/20221013212615_cascade_delete_on_share/migration.sql new file mode 100644 index 00000000..1ca00d6d --- /dev/null +++ b/backend/prisma/migrations/20221013212615_cascade_delete_on_share/migration.sql @@ -0,0 +1,14 @@ +-- RedefineTables +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_RefreshToken" ( + "token" TEXT NOT NULL PRIMARY KEY, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "expiresAt" DATETIME NOT NULL, + "userId" TEXT NOT NULL, + CONSTRAINT "RefreshToken_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE +); +INSERT INTO "new_RefreshToken" ("createdAt", "expiresAt", "token", "userId") SELECT "createdAt", "expiresAt", "token", "userId" FROM "RefreshToken"; +DROP TABLE "RefreshToken"; +ALTER TABLE "new_RefreshToken" RENAME TO "RefreshToken"; +PRAGMA foreign_key_check; +PRAGMA foreign_keys=ON; diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index 31f749ee..883832bd 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -28,7 +28,7 @@ model RefreshToken { expiresAt DateTime userId String - user User @relation(fields: [userId], references: [id]) + user User @relation(fields: [userId], references: [id], onDelete: Cascade) } model Share {