27 lines
671 B
Python
27 lines
671 B
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
from pathlib import Path
|
|
|
|
from alembic import command
|
|
from alembic.config import Config
|
|
|
|
from app.config import BACKEND_ROOT, data_dir, installed
|
|
|
|
logger = logging.getLogger("decom")
|
|
|
|
|
|
def migrate() -> None:
|
|
data_dir().mkdir(parents=True, exist_ok=True)
|
|
config = Config(str(Path(BACKEND_ROOT) / "alembic.ini"))
|
|
config.set_main_option("script_location", str(Path(BACKEND_ROOT) / "alembic"))
|
|
config.attributes["configure_logger"] = False
|
|
command.upgrade(config, "head")
|
|
|
|
|
|
def init_db() -> None:
|
|
if not installed():
|
|
logger.info("尚未安装,等待安装页")
|
|
return
|
|
migrate()
|