From 0700d374698ed20958ab2606b428e6d79077cf36 Mon Sep 17 00:00:00 2001 From: Rephl3x Date: Sun, 24 May 2026 16:55:18 +1200 Subject: [PATCH] Fix requests cache migration on legacy databases --- backend/app/db.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/backend/app/db.py b/backend/app/db.py index 9d2c156..fe7397e 100644 --- a/backend/app/db.py +++ b/backend/app/db.py @@ -418,12 +418,16 @@ def init_db() -> None: ON requests_cache (updated_at DESC, request_id DESC) """ ) - conn.execute( - """ - CREATE INDEX IF NOT EXISTS idx_requests_cache_requested_by_id_created_at - ON requests_cache (requested_by_id, created_at DESC, request_id DESC) - """ - ) + try: + conn.execute( + """ + CREATE INDEX IF NOT EXISTS idx_requests_cache_requested_by_id_created_at + ON requests_cache (requested_by_id, created_at DESC, request_id DESC) + """ + ) + except sqlite3.OperationalError: + # Older databases may not have requested_by_id until later migrations run. + pass conn.execute( """ CREATE INDEX IF NOT EXISTS idx_requests_cache_requested_by_norm_created_at