Add updated_at column and trigger for Qdrant re-sync detection

Adds updated_at TIMESTAMPTZ to ocr_jobs, stamped automatically by a
BEFORE UPDATE trigger. The sync process can use updated_at > qdrant_synced_at
to detect jobs that need re-ingestion after edits or reviews.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Aaron Roberts
2026-06-19 23:12:33 +01:00
parent 38ac36b18e
commit 91c134faa7

View File

@@ -58,6 +58,25 @@ def init_db():
ALTER TABLE ocr_jobs ALTER TABLE ocr_jobs
ADD COLUMN IF NOT EXISTS qdrant_synced_at TIMESTAMPTZ ADD COLUMN IF NOT EXISTS qdrant_synced_at TIMESTAMPTZ
""") """)
cur.execute("""
ALTER TABLE ocr_jobs
ADD COLUMN IF NOT EXISTS updated_at TIMESTAMPTZ
""")
# Trigger function: stamp updated_at on every row update
cur.execute("""
CREATE OR REPLACE FUNCTION set_updated_at()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql
""")
cur.execute("""
CREATE OR REPLACE TRIGGER ocr_jobs_set_updated_at
BEFORE UPDATE ON ocr_jobs
FOR EACH ROW EXECUTE FUNCTION set_updated_at()
""")
# Unique constraint: prevent duplicate (author, chapter, page) submissions. # Unique constraint: prevent duplicate (author, chapter, page) submissions.
# Applies only when all three fields are non-null. # Applies only when all three fields are non-null.
cur.execute(""" cur.execute("""