From febdf414694e65080b51feac0aecfb48ec8023df Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Mar 2026 15:09:32 +0000 Subject: [PATCH] fix(db): check column existence before creating performance indexes _ensure_indexes() now verifies the target column exists in the table before executing CREATE INDEX IF NOT EXISTS. This prevents failures when migrating legacy database schemas that don't yet have all columns (e.g. files table without created_at or mime_type). Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> --- app/database.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/database.py b/app/database.py index 61492804..83de3f1a 100644 --- a/app/database.py +++ b/app/database.py @@ -188,10 +188,14 @@ def _ensure_indexes(engine: Any, inspector: Any) -> None: ] table_names = inspector.get_table_names() + columns_by_table: dict[str, set[str]] = {} with engine.begin() as conn: for idx_name, table, column in _PERF_INDEXES: if table in table_names: - conn.execute(text(f"CREATE INDEX IF NOT EXISTS {idx_name} ON {table} ({column})")) + if table not in columns_by_table: + columns_by_table[table] = {col["name"] for col in inspector.get_columns(table)} + if column in columns_by_table[table]: + conn.execute(text(f"CREATE INDEX IF NOT EXISTS {idx_name} ON {table} ({column})")) logger.info("Performance indexes ensured")