feat: 用安装页和编排完成部署,并整理登录页
This commit is contained in:
+11
-22
@@ -1,37 +1,26 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from alembic import command
|
||||
from alembic.config import Config
|
||||
from sqlalchemy import select
|
||||
|
||||
from app.config import BACKEND_ROOT, admin_password, admin_username
|
||||
from app.db import session_scope
|
||||
from app.models import AppSetting, User
|
||||
from app.security import hash_password
|
||||
from app.config import BACKEND_ROOT, data_dir, installed
|
||||
|
||||
logger = logging.getLogger("decom")
|
||||
|
||||
|
||||
def init_db() -> None:
|
||||
from app.config import DATA_DIR
|
||||
|
||||
DATA_DIR.mkdir(parents=True, exist_ok=True)
|
||||
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")
|
||||
with session_scope() as session:
|
||||
if session.get(AppSetting, 1) is None:
|
||||
session.add(AppSetting(id=1, login_mode="local", credential_refresh_seconds=300))
|
||||
if admin_username() and admin_password() and session.scalar(select(User).where(User.role == "admin")) is None:
|
||||
session.add(
|
||||
User(
|
||||
username=admin_username(),
|
||||
password_hash=hash_password(admin_password()),
|
||||
role="admin",
|
||||
)
|
||||
)
|
||||
logger.info("已创建管理员 %s", admin_username())
|
||||
|
||||
|
||||
def init_db() -> None:
|
||||
if not installed():
|
||||
logger.info("尚未安装,等待安装页")
|
||||
return
|
||||
migrate()
|
||||
|
||||
Reference in New Issue
Block a user