fix: 문서 삭제 시 processing_queue FK 제약 해결 + 변환본/preview 함께 삭제

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-04-03 13:51:35 +09:00
parent 5153169d5d
commit 7f5e09096a

View File

@@ -380,10 +380,25 @@ async def delete_document(
raise HTTPException(status_code=404, detail="문서를 찾을 수 없습니다")
if delete_file:
# 원본 파일 삭제
file_path = Path(settings.nas_mount_path) / doc.file_path
if file_path.exists():
file_path.unlink()
# 변환본 삭제
if doc.original_path:
orig = Path(settings.nas_mount_path) / doc.original_path
if orig.exists():
orig.unlink()
# preview 캐시 삭제
preview = Path(settings.nas_mount_path) / "PKM" / ".preview" / f"{doc_id}.pdf"
if preview.exists():
preview.unlink()
# 관련 processing_queue 먼저 삭제 (FK 제약)
from sqlalchemy import delete as sql_delete
await session.execute(
sql_delete(ProcessingQueue).where(ProcessingQueue.document_id == doc_id)
)
await session.delete(doc)
await session.commit()