From 1b0f5866a19adf4957ddc20f85e81ba658b683f0 Mon Sep 17 00:00:00 2001 From: "simon.franken" Date: Mon, 23 Feb 2026 15:32:31 +0100 Subject: [PATCH] Restore onDelete: Cascade on Project->Client and TimeEntry->Project Direct database deletes should still cascade to avoid orphaned records. The migration now only adds the three deleted_at columns without touching the existing FK constraints. --- .../20260223200000_add_soft_delete/migration.sql | 12 ------------ backend/prisma/schema.prisma | 4 ++-- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/backend/prisma/migrations/20260223200000_add_soft_delete/migration.sql b/backend/prisma/migrations/20260223200000_add_soft_delete/migration.sql index 2e1a248..9ff874e 100644 --- a/backend/prisma/migrations/20260223200000_add_soft_delete/migration.sql +++ b/backend/prisma/migrations/20260223200000_add_soft_delete/migration.sql @@ -6,15 +6,3 @@ ALTER TABLE "projects" ADD COLUMN "deleted_at" TIMESTAMP(3); -- AlterTable: add deleted_at column to time_entries ALTER TABLE "time_entries" ADD COLUMN "deleted_at" TIMESTAMP(3); - --- DropForeignKey: remove cascade from projects -> clients -ALTER TABLE "projects" DROP CONSTRAINT "projects_client_id_fkey"; - --- DropForeignKey: remove cascade from time_entries -> projects -ALTER TABLE "time_entries" DROP CONSTRAINT "time_entries_project_id_fkey"; - --- AddForeignKey: re-add without onDelete cascade -ALTER TABLE "projects" ADD CONSTRAINT "projects_client_id_fkey" FOREIGN KEY ("client_id") REFERENCES "clients"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey: re-add without onDelete cascade -ALTER TABLE "time_entries" ADD CONSTRAINT "time_entries_project_id_fkey" FOREIGN KEY ("project_id") REFERENCES "projects"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index 0932af2..5f8fc9e 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -53,7 +53,7 @@ model Project { userId String @map("user_id") @db.VarChar(255) user User @relation(fields: [userId], references: [id], onDelete: Cascade) clientId String @map("client_id") - client Client @relation(fields: [clientId], references: [id]) + client Client @relation(fields: [clientId], references: [id], onDelete: Cascade) timeEntries TimeEntry[] ongoingTimers OngoingTimer[] @@ -76,7 +76,7 @@ model TimeEntry { userId String @map("user_id") @db.VarChar(255) user User @relation(fields: [userId], references: [id], onDelete: Cascade) projectId String @map("project_id") - project Project @relation(fields: [projectId], references: [id]) + project Project @relation(fields: [projectId], references: [id], onDelete: Cascade) @@index([userId]) @@index([userId, startTime])