fix
This commit is contained in:
@@ -294,6 +294,62 @@ def _ensure_git_server_configs_columns(bind_engine):
|
||||
# [/DEF:_ensure_git_server_configs_columns:Function]
|
||||
|
||||
|
||||
# [DEF:_ensure_auth_users_columns:Function]
|
||||
# @COMPLEXITY: 3
|
||||
# @PURPOSE: Applies additive schema upgrades for auth users table.
|
||||
# @PRE: bind_engine points to authentication database.
|
||||
# @POST: Missing columns are added without data loss.
|
||||
def _ensure_auth_users_columns(bind_engine):
|
||||
with belief_scope("_ensure_auth_users_columns"):
|
||||
table_name = "users"
|
||||
inspector = inspect(bind_engine)
|
||||
if table_name not in inspector.get_table_names():
|
||||
return
|
||||
|
||||
existing_columns = {
|
||||
str(column.get("name") or "").strip()
|
||||
for column in inspector.get_columns(table_name)
|
||||
}
|
||||
|
||||
alter_statements = []
|
||||
if "full_name" not in existing_columns:
|
||||
alter_statements.append(
|
||||
"ALTER TABLE users ADD COLUMN full_name VARCHAR"
|
||||
)
|
||||
if "is_ad_user" not in existing_columns:
|
||||
alter_statements.append(
|
||||
"ALTER TABLE users ADD COLUMN is_ad_user BOOLEAN NOT NULL DEFAULT FALSE"
|
||||
)
|
||||
|
||||
if not alter_statements:
|
||||
logger.reason(
|
||||
"Auth users schema already up to date",
|
||||
extra={"table": table_name, "columns": sorted(existing_columns)},
|
||||
)
|
||||
return
|
||||
|
||||
logger.reason(
|
||||
"Applying additive auth users schema migration",
|
||||
extra={"table": table_name, "statements": alter_statements},
|
||||
)
|
||||
|
||||
try:
|
||||
with bind_engine.begin() as connection:
|
||||
for statement in alter_statements:
|
||||
connection.execute(text(statement))
|
||||
logger.reason(
|
||||
"Auth users schema migration completed",
|
||||
extra={"table": table_name, "added_columns": [stmt.split(" ADD COLUMN ", 1)[1].split()[0] for stmt in alter_statements]},
|
||||
)
|
||||
except Exception as migration_error:
|
||||
logger.warning(
|
||||
"[database][EXPLORE] Auth users additive migration failed: %s",
|
||||
migration_error,
|
||||
)
|
||||
raise
|
||||
# [/DEF:_ensure_auth_users_columns:Function]
|
||||
|
||||
|
||||
# [DEF:ensure_connection_configs_table:Function]
|
||||
# @COMPLEXITY: 3
|
||||
# @PURPOSE: Ensures the external connection registry table exists in the main database.
|
||||
@@ -327,6 +383,7 @@ def init_db():
|
||||
_ensure_llm_validation_results_columns(engine)
|
||||
_ensure_user_dashboard_preferences_health_columns(engine)
|
||||
_ensure_git_server_configs_columns(engine)
|
||||
_ensure_auth_users_columns(auth_engine)
|
||||
ensure_connection_configs_table(engine)
|
||||
# [/DEF:init_db:Function]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user