零 Node 部署、超级管理员,并完善本地构建发布文档。

- FastAPI 单进程托管 frontend/dist,systemd 替代 PM2

- 超级管理员 admin、注册开关与用户管理

- README/DEPLOY/USAGE 说明:改代码须本地构建 dist 后 push,服务器 update.sh

- 提交 frontend/dist 与 build-frontend 脚本
This commit is contained in:
dekun
2026-06-28 13:19:41 +08:00
parent a3d4875bde
commit f1ad4273f4
34 changed files with 1567 additions and 268 deletions
+15
View File
@@ -1,5 +1,6 @@
from sqlalchemy import inspect, text
from app.core.config import settings
from app.core.database import engine
@@ -18,3 +19,17 @@ def run_migrations() -> None:
"NOT NULL DEFAULT 'junior_high'"
)
)
if "users" in inspector.get_table_names():
user_columns = {col["name"] for col in inspector.get_columns("users")}
if "is_superuser" not in user_columns:
with engine.begin() as conn:
conn.execute(
text("ALTER TABLE users ADD COLUMN is_superuser BOOLEAN NOT NULL DEFAULT FALSE")
)
conn.execute(
text(
f"UPDATE users SET is_superuser = TRUE "
f"WHERE username = '{settings.ADMIN_DEFAULT_USERNAME}'"
)
)
+22 -1
View File
@@ -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()