mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-07 00:16:57 +08:00
refactor: unify database readiness lifecycle
This commit is contained in:
@@ -11,7 +11,7 @@ from sqlalchemy import inspect
|
||||
from sqlalchemy.engine import Engine
|
||||
|
||||
from app.runtime.config import settings
|
||||
from app.db import Base
|
||||
from app.db.base import Base
|
||||
from app.db.engine import get_engine
|
||||
from app.db.models import load_all_models
|
||||
from app.runtime.log import logger
|
||||
@@ -121,6 +121,18 @@ def prepare_database(*, before_alembic: Callable[[], None] | None = None) -> Non
|
||||
update_db(alembic_cfg)
|
||||
|
||||
|
||||
def verify_database_revision() -> None:
|
||||
"""确认活动数据库已位于当前唯一 Alembic head,否则阻止 readiness。"""
|
||||
engine = get_engine()
|
||||
alembic_cfg = _build_alembic_config(engine)
|
||||
_, current_heads, target_heads = _migration_state(engine, alembic_cfg)
|
||||
if set(current_heads) != set(target_heads):
|
||||
raise RuntimeError(
|
||||
"数据库迁移完成后 revision 仍未到达当前 head:"
|
||||
f"current={current_heads}, target={target_heads}"
|
||||
)
|
||||
|
||||
|
||||
def init_db():
|
||||
"""
|
||||
初始化数据库
|
||||
|
||||
Reference in New Issue
Block a user