subagents
This commit is contained in:
@@ -369,6 +369,69 @@ def ensure_connection_configs_table(bind_engine):
|
||||
# [/DEF:ensure_connection_configs_table:Function]
|
||||
|
||||
|
||||
# [DEF:_ensure_filter_source_enum_values:Function]
|
||||
# @COMPLEXITY: 3
|
||||
# @PURPOSE: Adds missing FilterSource enum values to the PostgreSQL native filtersource type.
|
||||
# @PRE: bind_engine points to application database with imported_filters table.
|
||||
# @POST: New enum values are available without data loss.
|
||||
def _ensure_filter_source_enum_values(bind_engine):
|
||||
with belief_scope("_ensure_filter_source_enum_values"):
|
||||
try:
|
||||
with bind_engine.connect() as connection:
|
||||
# Check if the native enum type exists
|
||||
result = connection.execute(
|
||||
text(
|
||||
"SELECT t.typname FROM pg_type t "
|
||||
"JOIN pg_namespace n ON t.typnamespace = n.oid "
|
||||
"WHERE t.typname = 'filtersource' AND n.nspname = 'public'"
|
||||
)
|
||||
)
|
||||
if result.fetchone() is None:
|
||||
logger.reason("filtersource enum type does not exist yet; skipping migration")
|
||||
return
|
||||
|
||||
# Get existing enum values
|
||||
result = connection.execute(
|
||||
text(
|
||||
"SELECT e.enumlabel FROM pg_enum e "
|
||||
"JOIN pg_type t ON e.enumtypid = t.oid "
|
||||
"WHERE t.typname = 'filtersource' "
|
||||
"ORDER BY e.enumsortorder"
|
||||
)
|
||||
)
|
||||
existing_values = {row[0] for row in result.fetchall()}
|
||||
|
||||
required_values = ["SUPERSET_PERMALINK", "SUPERSET_NATIVE_FILTERS_KEY"]
|
||||
missing_values = [v for v in required_values if v not in existing_values]
|
||||
|
||||
if not missing_values:
|
||||
logger.reason(
|
||||
"filtersource enum already up to date",
|
||||
extra={"existing": sorted(existing_values)},
|
||||
)
|
||||
return
|
||||
|
||||
logger.reason(
|
||||
"Adding missing values to filtersource enum",
|
||||
extra={"missing": missing_values},
|
||||
)
|
||||
for value in missing_values:
|
||||
connection.execute(
|
||||
text(f"ALTER TYPE filtersource ADD VALUE IF NOT EXISTS '{value}'")
|
||||
)
|
||||
connection.commit()
|
||||
logger.reason(
|
||||
"filtersource enum migration completed",
|
||||
extra={"added": missing_values},
|
||||
)
|
||||
except Exception as migration_error:
|
||||
logger.warning(
|
||||
"[database][EXPLORE] FilterSource enum additive migration failed: %s",
|
||||
migration_error,
|
||||
)
|
||||
# [/DEF:_ensure_filter_source_enum_values:Function]
|
||||
|
||||
|
||||
# [DEF:init_db:Function]
|
||||
# @COMPLEXITY: 3
|
||||
# @PURPOSE: Initializes the database by creating all tables.
|
||||
@@ -386,6 +449,7 @@ def init_db():
|
||||
_ensure_git_server_configs_columns(engine)
|
||||
_ensure_auth_users_columns(auth_engine)
|
||||
ensure_connection_configs_table(engine)
|
||||
_ensure_filter_source_enum_values(engine)
|
||||
# [/DEF:init_db:Function]
|
||||
|
||||
# [DEF:get_db:Function]
|
||||
|
||||
Reference in New Issue
Block a user