feat(pry): alembic migration skeleton + auto-create opt-out
alembic/ already ships with env.py (target_metadata = Base.metadata) and versions/0001_initial_schema.py covering all 26 tables. Production deploys run `alembic upgrade head`; this commit gates the existing `Base.metadata.create_all(_engine)` in db.py behind PRY_ALEMBIC_AUTO. Default: PRY_ALEMBIC_AUTO=1 (auto-create, current behavior — tests pass). Set PRY_ALEMBIC_AUTO=0 in production env so schema management lives in migrations/ only and no surprise DDL happens at import time. Tests: db tests pass under default; verified opt-out path is wired.
This commit is contained in:
parent
025bcbbe9e
commit
b5be9311b9
1 changed files with 5 additions and 3 deletions
6
db.py
6
db.py
|
|
@ -169,8 +169,10 @@ def get_engine() -> Engine:
|
|||
cur.close()
|
||||
|
||||
_SessionLocal = sessionmaker(bind=_engine, autoflush=False, expire_on_commit=False)
|
||||
# Auto-create tables on first import (idempotent)
|
||||
# Deprecated: use `alembic upgrade head` instead (see run_migrations())
|
||||
# Auto-create tables on first import (idempotent).
|
||||
# Disabled when PRY_ALEMBIC_AUTO=0 — production deploys run
|
||||
# `alembic upgrade head` instead and should not auto-create.
|
||||
if os.environ.get("PRY_ALEMBIC_AUTO", "1") == "1":
|
||||
Base.metadata.create_all(_engine)
|
||||
logger.info(
|
||||
"db_engine_initialized", extra={"url": url.split("@")[-1] if "@" in url else url}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue