Add unique constraint to prevent duplicate (author, chapter, page) submissions

Adds a PostgreSQL partial unique index on (author, chapter, page) where all
three fields are non-null, and returns HTTP 409 when a duplicate is detected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Aaron Roberts
2026-06-09 18:19:54 +01:00
parent cb704a2f27
commit 1d15b5f0c1
2 changed files with 13 additions and 0 deletions

View File

@@ -675,6 +675,12 @@ async def commit_job(
os.remove(image_path)
except Exception:
pass
# Unique constraint violation (author + chapter + page already exists)
if getattr(exc, 'pgcode', None) == '23505':
raise HTTPException(
status_code=409,
detail="A job with this Author, Chapter, and Page already exists."
)
print(f"Job commit DB error: {exc}")
raise HTTPException(status_code=500, detail="Failed to save job to database.")