From 9337a4cecd37086e94551b990357a91e3e874f19 Mon Sep 17 00:00:00 2001 From: busya Date: Tue, 26 May 2026 19:00:04 +0300 Subject: [PATCH] fix: add missing schema columns and Alembic model imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added 4 missing columns to _ensure_translation_jobs_columns() inline migration: target_language_column, target_source_column, target_source_language_column, disable_reasoning — these were in the SQLAlchemy model but had no Alembic migration or _ensure_*() coverage - Added missing api_key, assistant, clean_release model imports to alembic/env.py so autogenerate can see all tables --- backend/alembic/env.py | 3 ++ backend/src/core/database.py | 65 ++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/backend/alembic/env.py b/backend/alembic/env.py index d8e87e53..e79cf439 100644 --- a/backend/alembic/env.py +++ b/backend/alembic/env.py @@ -30,7 +30,10 @@ from src.models.mapping import Base # Import ALL model modules so their tables are registered in Base.metadata from src.models import ( # noqa: F401 + api_key, + assistant, auth, + clean_release, dashboard, dataset_review_pkg, filter_state, diff --git a/backend/src/core/database.py b/backend/src/core/database.py index f8be988e..510fbedd 100644 --- a/backend/src/core/database.py +++ b/backend/src/core/database.py @@ -527,6 +527,71 @@ def _ensure_translation_jobs_columns(bind_engine): extra={"error": str(migration_error)}, ) + # Columns added to model AFTER initial Alembic migration — no Alembic migration exists + if "target_language_column" not in existing_columns: + try: + with bind_engine.begin() as connection: + connection.execute( + text( + "ALTER TABLE translation_jobs " + "ADD COLUMN target_language_column VARCHAR" + ) + ) + logger.reflect("Added target_language_column to translation_jobs") + except Exception as migration_error: + logger.explore( + "Failed to add target_language_column to translation_jobs", + extra={"error": str(migration_error)}, + ) + + if "target_source_column" not in existing_columns: + try: + with bind_engine.begin() as connection: + connection.execute( + text( + "ALTER TABLE translation_jobs " + "ADD COLUMN target_source_column VARCHAR" + ) + ) + logger.reflect("Added target_source_column to translation_jobs") + except Exception as migration_error: + logger.explore( + "Failed to add target_source_column to translation_jobs", + extra={"error": str(migration_error)}, + ) + + if "target_source_language_column" not in existing_columns: + try: + with bind_engine.begin() as connection: + connection.execute( + text( + "ALTER TABLE translation_jobs " + "ADD COLUMN target_source_language_column VARCHAR" + ) + ) + logger.reflect("Added target_source_language_column to translation_jobs") + except Exception as migration_error: + logger.explore( + "Failed to add target_source_language_column to translation_jobs", + extra={"error": str(migration_error)}, + ) + + if "disable_reasoning" not in existing_columns: + try: + with bind_engine.begin() as connection: + connection.execute( + text( + "ALTER TABLE translation_jobs " + "ADD COLUMN disable_reasoning BOOLEAN NOT NULL DEFAULT FALSE" + ) + ) + logger.reflect("Added disable_reasoning column to translation_jobs") + except Exception as migration_error: + logger.explore( + "Failed to add disable_reasoning to translation_jobs", + extra={"error": str(migration_error)}, + ) + def _ensure_dataset_review_session_columns(bind_engine): with belief_scope("_ensure_dataset_review_session_columns"):