零 Node 部署、超级管理员,并完善本地构建发布文档。
- FastAPI 单进程托管 frontend/dist,systemd 替代 PM2 - 超级管理员 admin、注册开关与用户管理 - README/DEPLOY/USAGE 说明:改代码须本地构建 dist 后 push,服务器 update.sh - 提交 frontend/dist 与 build-frontend 脚本
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.models.user import Subject
|
||||
from app.core.config import settings
|
||||
from app.core.security import get_password_hash
|
||||
from app.models.user import Subject, SystemSettings, User
|
||||
|
||||
DEFAULT_SUBJECTS = [
|
||||
"语文",
|
||||
@@ -21,3 +23,22 @@ def seed_subjects(db: Session) -> None:
|
||||
if name not in existing:
|
||||
db.add(Subject(name=name))
|
||||
db.commit()
|
||||
|
||||
|
||||
def seed_admin_and_settings(db: Session) -> None:
|
||||
if db.get(SystemSettings, 1) is None:
|
||||
db.add(SystemSettings(id=1, registration_enabled=True))
|
||||
|
||||
admin = db.query(User).filter(User.username == settings.ADMIN_DEFAULT_USERNAME).first()
|
||||
if admin is None:
|
||||
db.add(
|
||||
User(
|
||||
username=settings.ADMIN_DEFAULT_USERNAME,
|
||||
password_hash=get_password_hash(settings.ADMIN_DEFAULT_PASSWORD),
|
||||
is_superuser=True,
|
||||
)
|
||||
)
|
||||
elif not admin.is_superuser:
|
||||
admin.is_superuser = True
|
||||
|
||||
db.commit()
|
||||
|
||||
Reference in New Issue
Block a user