fix(schema): cascade-delete VideoConfig/LintResult/BulkJobItem/VideoPlaylist with their Video

Channel import crashed on the hard-delete purge path (videos confirmed
gone from YouTube for 30+ days): prisma.video.deleteMany() hit a FK
violation on VideoConfig_videoId_fkey. All four required relations
pointing at Video had no onDelete behavior set, defaulting to RESTRICT
- any of the four would have hit the same crash, not just VideoConfig.
First real channel import against a real, aged dataset is what
surfaced this; nothing had exercised the 30-day hard-delete path before.
This commit is contained in:
2026-08-11 17:14:20 +02:00
parent 0ac1ca3b08
commit 49cfe2d8e0
2 changed files with 27 additions and 4 deletions
@@ -0,0 +1,23 @@
-- DropForeignKey
ALTER TABLE "BulkJobItem" DROP CONSTRAINT "BulkJobItem_videoId_fkey";
-- DropForeignKey
ALTER TABLE "LintResult" DROP CONSTRAINT "LintResult_videoId_fkey";
-- DropForeignKey
ALTER TABLE "VideoConfig" DROP CONSTRAINT "VideoConfig_videoId_fkey";
-- DropForeignKey
ALTER TABLE "VideoPlaylist" DROP CONSTRAINT "VideoPlaylist_videoId_fkey";
-- AddForeignKey
ALTER TABLE "VideoConfig" ADD CONSTRAINT "VideoConfig_videoId_fkey" FOREIGN KEY ("videoId") REFERENCES "Video"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "LintResult" ADD CONSTRAINT "LintResult_videoId_fkey" FOREIGN KEY ("videoId") REFERENCES "Video"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "BulkJobItem" ADD CONSTRAINT "BulkJobItem_videoId_fkey" FOREIGN KEY ("videoId") REFERENCES "Video"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "VideoPlaylist" ADD CONSTRAINT "VideoPlaylist_videoId_fkey" FOREIGN KEY ("videoId") REFERENCES "Video"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+4 -4
View File
@@ -174,7 +174,7 @@ enum LintStatus {
model VideoConfig {
id String @id @default(cuid())
videoId String @unique
video Video @relation(fields: [videoId], references: [id])
video Video @relation(fields: [videoId], references: [id], onDelete: Cascade)
templateId String?
blockOrder Json
blockOverrides Json
@@ -312,7 +312,7 @@ model SavedView {
model LintResult {
id String @id @default(cuid())
videoId String
video Video @relation(fields: [videoId], references: [id])
video Video @relation(fields: [videoId], references: [id], onDelete: Cascade)
ruleCode String
severity LintSeverity
targetField String?
@@ -369,7 +369,7 @@ model BulkJobItem {
bulkJobId String
bulkJob BulkJob @relation(fields: [bulkJobId], references: [id])
videoId String
video Video @relation(fields: [videoId], references: [id])
video Video @relation(fields: [videoId], references: [id], onDelete: Cascade)
beforeSnapshot Json?
afterSnapshot Json?
status String @default("pending")
@@ -415,7 +415,7 @@ model VideoPlaylist {
videoId String
playlistId String
position Int?
video Video @relation(fields: [videoId], references: [id])
video Video @relation(fields: [videoId], references: [id], onDelete: Cascade)
playlist Playlist @relation(fields: [playlistId], references: [id])
@@id([videoId, playlistId])