fix(migrations): harden BAT-025 PostgreSQL verification

This commit is contained in:
Hermes Agent
2026-07-15 17:58:18 +09:00
parent 1909caa22c
commit d48279f7ab
6 changed files with 350 additions and 142 deletions
+11 -1
View File
@@ -16,6 +16,10 @@ def get_alembic_config(settings: Settings) -> Config:
config = Config(str(project_root / "alembic.ini"))
config.set_main_option("script_location", str(project_root / "migrations"))
config.set_main_option("sqlalchemy.url", settings.active_database_url.replace("%", "%%"))
# migrations/env.py must use this explicit settings object instead of the
# process-global cached Settings. This keeps programmatic callers (notably
# isolated integration tests and runtime bootstrap) on their requested DB.
config.attributes["portfoliohub_settings"] = settings
return config
@@ -29,7 +33,13 @@ def bootstrap_or_upgrade_to_head(settings: Settings) -> str:
return "head"
if _has_legacy_portfolio_schema(settings):
command.stamp(get_alembic_config(settings), "head")
# Runtime ensure_schema() can create the BAT-025 columns before Alembic is
# introduced. Stamp only the revision immediately before BAT-025, then run
# the real upgrade so 0028 backfills a nullable pre-created `source` and
# converges constraints/defaults without replaying the older DDL chain.
config = get_alembic_config(settings)
command.stamp(config, "20260628_0027")
command.upgrade(config, "head")
return "head"
upgrade_to_head(settings)