fix: 문서 삭제 시 processing_queue FK 제약 해결 + 변환본/preview 함께 삭제
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -380,10 +380,25 @@ async def delete_document(
|
|||||||
raise HTTPException(status_code=404, detail="문서를 찾을 수 없습니다")
|
raise HTTPException(status_code=404, detail="문서를 찾을 수 없습니다")
|
||||||
|
|
||||||
if delete_file:
|
if delete_file:
|
||||||
|
# 원본 파일 삭제
|
||||||
file_path = Path(settings.nas_mount_path) / doc.file_path
|
file_path = Path(settings.nas_mount_path) / doc.file_path
|
||||||
if file_path.exists():
|
if file_path.exists():
|
||||||
file_path.unlink()
|
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.delete(doc)
|
||||||
await session.commit()
|
await session.commit()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user