Move schema evolution to Alembic with auto-upgrade on API start.

Extract shared brownfield patches, add the legacy revision, and default to upgrade-head plus skip of duplicate inline DDL (with legacy fallback if Alembic fails).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-08-02 16:41:56 +08:00
parent 6e8003be5c
commit 57b3faf9fb
8 changed files with 503 additions and 343 deletions

View file

@ -133,8 +133,11 @@ class Settings(BaseSettings):
# Async audit writer; sample_n>1 keeps 1/N of generic http.* events.
audit_async: bool = True
audit_sample_n: int = 1
# Prefer Alembic; when true, skip ad-hoc ALTER TABLE on startup (create_all still runs).
skip_legacy_startup_ddl: bool = False
# Prefer Alembic on API start; brownfield patches live in schema_patches + revisions.
# Auth column ensures still run as a safety net before bootstrap.
skip_legacy_startup_ddl: bool = True
# Run `alembic upgrade head` during API startup (recommended default).
alembic_upgrade_on_start: bool = True
# Optional dedicated SQLAlchemy URL for /v1/sql/* (read-only DB role recommended).
sql_readonly_database_url: str = ""
# When false, API skips config_sync / lldp / port_traffic schedulers (run `python -m netx_api.worker`).