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 {