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:
@@ -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("""
|
||||||
|
|||||||
Reference in New Issue
Block a user