Persist runtime config in app db and seed from env

This commit is contained in:
2026-04-20 15:56:10 +02:00
parent 3f7c9e43d9
commit 179aae264e
21 changed files with 921 additions and 125 deletions
+7 -8
View File
@@ -13,7 +13,7 @@ if str(PROJECT_ROOT) not in sys.path:
from app.config import get_settings
APP_BASELINE_REVISION = "20260420_03_app_auth_baseline"
APP_BASELINE_REVISION = "20260420_04_app_config_table"
class AppDatabaseAdoptionError(RuntimeError):
@@ -102,13 +102,10 @@ def adopt_or_initialize_app_db(database_url: str) -> str:
if database_path.exists():
if _alembic_version_table_exists(database_path):
current_revision = _fetch_alembic_revision(database_path)
if current_revision != APP_BASELINE_REVISION:
raise AppDatabaseAdoptionError(
"App DB is already Alembic-managed but revision does not match "
f"the expected baseline: expected {APP_BASELINE_REVISION}, "
f"got {current_revision}"
)
return "already_managed"
if current_revision == APP_BASELINE_REVISION:
return "already_managed"
command.upgrade(alembic_config, "head")
return "upgraded"
existing_tables = _list_user_tables(database_path)
if existing_tables:
@@ -127,6 +124,8 @@ def main() -> None:
result = adopt_or_initialize_app_db(settings.app_database_url)
if result == "initialized":
print("Initialized a new app DB via Alembic upgrade head.")
elif result == "upgraded":
print("Upgraded existing app DB to the expected Alembic head revision.")
else:
print("App DB is already Alembic-managed at the expected baseline revision.")