refactor
This commit is contained in:
@@ -506,6 +506,62 @@ def _ensure_translation_jobs_columns(bind_engine):
|
||||
)
|
||||
raise
|
||||
|
||||
if "target_database_id" not in existing_columns:
|
||||
try:
|
||||
with bind_engine.begin() as connection:
|
||||
connection.execute(
|
||||
text(
|
||||
"ALTER TABLE translation_jobs "
|
||||
"ADD COLUMN target_database_id VARCHAR"
|
||||
)
|
||||
)
|
||||
logger.reflect(
|
||||
"Added target_database_id column to translation_jobs",
|
||||
)
|
||||
except Exception as migration_error:
|
||||
logger.explore(
|
||||
"Failed to add target_database_id to translation_jobs",
|
||||
extra={"error": str(migration_error)},
|
||||
)
|
||||
raise
|
||||
|
||||
|
||||
# [DEF:_ensure_translation_records_columns:Function]
|
||||
# @PURPOSE: Add source_data JSON column to translation_records and translation_preview_records.
|
||||
# @PRE: bind_engine points to the application database.
|
||||
# @POST: source_data column exists on both tables.
|
||||
# @SIDE_EFFECT: Executes ALTER TABLE statements.
|
||||
def _ensure_translation_records_columns(bind_engine):
|
||||
with belief_scope("_ensure_translation_records_columns"):
|
||||
migrations = [
|
||||
("translation_records", "source_data",
|
||||
"ALTER TABLE translation_records ADD COLUMN source_data JSON"),
|
||||
("translation_preview_records", "source_data",
|
||||
"ALTER TABLE translation_preview_records ADD COLUMN source_data JSON"),
|
||||
]
|
||||
for table_name, column_name, alter_sql in migrations:
|
||||
inspector = inspect(bind_engine)
|
||||
if table_name not in inspector.get_table_names():
|
||||
continue
|
||||
existing_columns = {
|
||||
str(c.get("name") or "").strip()
|
||||
for c in inspector.get_columns(table_name)
|
||||
}
|
||||
if column_name not in existing_columns:
|
||||
try:
|
||||
with bind_engine.begin() as connection:
|
||||
connection.execute(text(alter_sql))
|
||||
logger.reflect(
|
||||
f"Added {column_name} column to {table_name}",
|
||||
)
|
||||
except Exception as migration_error:
|
||||
logger.explore(
|
||||
f"Failed to add {column_name} to {table_name}",
|
||||
extra={"error": str(migration_error)},
|
||||
)
|
||||
raise
|
||||
# [/DEF:_ensure_translation_records_columns:Function]
|
||||
|
||||
|
||||
def _ensure_dataset_review_session_columns(bind_engine):
|
||||
with belief_scope("_ensure_dataset_review_session_columns"):
|
||||
@@ -606,6 +662,7 @@ def init_db():
|
||||
_ensure_filter_source_enum_values(engine)
|
||||
_ensure_dataset_review_session_columns(engine)
|
||||
_ensure_translation_jobs_columns(engine)
|
||||
_ensure_translation_records_columns(engine)
|
||||
|
||||
|
||||
# [/DEF:init_db:Function]
|
||||
|
||||
Reference in New Issue
Block a user