fix alembic migration
This commit is contained in:
@@ -21,10 +21,27 @@ logger = get_logger(__name__)
|
||||
_API_DIR: Final[Path] = Path(__file__).resolve().parent.parent.parent
|
||||
|
||||
|
||||
def _repair_withdrawn_revision_stamp_if_needed() -> None:
|
||||
from sqlalchemy import create_engine
|
||||
|
||||
from app.core.alembic_revision_repair import try_repair_withdrawn_0020_revision
|
||||
from app.core.db import _database_url
|
||||
|
||||
engine = create_engine(_database_url())
|
||||
with engine.connect() as conn:
|
||||
if try_repair_withdrawn_0020_revision(conn):
|
||||
conn.commit()
|
||||
logger.warning(
|
||||
"alembic_version 曾为已撤回的 0020_*,已回退到 0018;"
|
||||
"将重新执行 0019_align_legacy_schema"
|
||||
)
|
||||
|
||||
|
||||
def _run_alembic_upgrade_once() -> None:
|
||||
from alembic.command import upgrade
|
||||
from alembic.config import Config
|
||||
|
||||
_repair_withdrawn_revision_stamp_if_needed()
|
||||
cfg = Config(str(_API_DIR / "alembic.ini"))
|
||||
upgrade(cfg, "head")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user