Ensure topo_folder.external_ref exists on API startup.

Alembic stamp-without-upgrade left brownfield DBs missing the column; always apply a small topology schema safety net before bootstrap.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-08-07 10:09:02 +08:00
parent 961d523479
commit 74672b733f
2 changed files with 27 additions and 1 deletions

View file

@ -10,6 +10,7 @@ from .db import Base, SessionLocal, engine
from .schema_patches import (
apply_all_legacy_startup_ddl,
apply_auth_schema_patches,
apply_topology_schema_safety_net,
run_alembic_upgrade_to_head,
)
from .security_bootstrap import assert_secure_defaults_or_exit
@ -54,8 +55,11 @@ def run_api_startup() -> None:
try:
with engine.begin() as conn:
apply_auth_schema_patches(conn)
# Critical topology columns even when full legacy DDL is skipped
# (e.g. alembic stamped head without applying domain patches).
apply_topology_schema_safety_net(conn)
except Exception:
_log.exception("startup: auth schema patches failed")
_log.exception("startup: auth/topology schema safety patches failed")
if skip_ddl and alembic_ok:
_log.info("startup: schema via Alembic (legacy inline DDL skipped)")
else: