fix(asset): remove dangerous cascades that orphan s3 files

This commit is contained in:
yiling
2026-05-23 23:44:24 +08:00
parent effec44870
commit 0053d3a22c
3 changed files with 76 additions and 3 deletions
@@ -0,0 +1,17 @@
-- DropForeignKey
ALTER TABLE "assets" DROP CONSTRAINT "assets_parent_id_fkey";
-- DropForeignKey
ALTER TABLE "assets" DROP CONSTRAINT "assets_project_id_fkey";
-- DropForeignKey
ALTER TABLE "assets" DROP CONSTRAINT "assets_target_id_fkey";
-- AddForeignKey
ALTER TABLE "assets" ADD CONSTRAINT "assets_parent_id_fkey" FOREIGN KEY ("parent_id") REFERENCES "assets"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "assets" ADD CONSTRAINT "assets_target_id_fkey" FOREIGN KEY ("target_id") REFERENCES "assets"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "assets" ADD CONSTRAINT "assets_project_id_fkey" FOREIGN KEY ("project_id") REFERENCES "projects"("id") ON DELETE SET NULL ON UPDATE CASCADE;
+3 -3
View File
@@ -363,11 +363,11 @@ model Asset {
updatedAt DateTime @updatedAt @map("updated_at")
parentId String? @map("parent_id")
parent Asset? @relation("AssetChildren", fields: [parentId], references: [id], onDelete: Cascade)
parent Asset? @relation("AssetChildren", fields: [parentId], references: [id])
children Asset[] @relation("AssetChildren")
targetId String? @map("target_id")
target Asset? @relation("SymlinkTarget", fields: [targetId], references: [id], onDelete: Cascade)
target Asset? @relation("SymlinkTarget", fields: [targetId], references: [id])
symlinks Asset[] @relation("SymlinkTarget")
metadataValues AssetMetadataValue[] @relation("AssetToMetadataValues")
@@ -379,7 +379,7 @@ model Asset {
task Task? @relation("TaskToAsset", fields: [taskId], references: [id])
projectId String? @map("project_id")
project Project? @relation("ProjectToAsset", fields: [projectId], references: [id], onDelete: Cascade)
project Project? @relation("ProjectToAsset", fields: [projectId], references: [id])
comments AssetComment[] @relation("AssetToComment")
commentAttachments AssetCommentAttachment[] @relation("AssetToCommentAttachment")