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:
@@ -6,15 +6,3 @@ ALTER TABLE "projects" ADD COLUMN "deleted_at" TIMESTAMP(3);
|
|||||||
|
|
||||||
-- AlterTable: add deleted_at column to time_entries
|
-- AlterTable: add deleted_at column to time_entries
|
||||||
ALTER TABLE "time_entries" ADD COLUMN "deleted_at" TIMESTAMP(3);
|
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;
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ model Project {
|
|||||||
userId String @map("user_id") @db.VarChar(255)
|
userId String @map("user_id") @db.VarChar(255)
|
||||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||||
clientId String @map("client_id")
|
clientId String @map("client_id")
|
||||||
client Client @relation(fields: [clientId], references: [id])
|
client Client @relation(fields: [clientId], references: [id], onDelete: Cascade)
|
||||||
|
|
||||||
timeEntries TimeEntry[]
|
timeEntries TimeEntry[]
|
||||||
ongoingTimers OngoingTimer[]
|
ongoingTimers OngoingTimer[]
|
||||||
@@ -76,7 +76,7 @@ model TimeEntry {
|
|||||||
userId String @map("user_id") @db.VarChar(255)
|
userId String @map("user_id") @db.VarChar(255)
|
||||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||||
projectId String @map("project_id")
|
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])
|
||||||
@@index([userId, startTime])
|
@@index([userId, startTime])
|
||||||
|
|||||||
Reference in New Issue
Block a user