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.
This commit is contained in:
simon.franken
2026-02-23 15:32:31 +01:00
parent 159022ef38
commit 1b0f5866a1
2 changed files with 2 additions and 14 deletions

View File

@@ -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;

View File

@@ -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])