fix: project create schema - owner_name auto-fill from owner_id, sub/related projects as list

This commit is contained in:
Zhi
2026-03-12 10:52:46 +00:00
parent d5bf47f4fc
commit 1eb90cd61c
6 changed files with 121 additions and 10 deletions

View File

@@ -70,7 +70,7 @@ def init_admin_user(db: Session, admin_cfg: dict) -> models.User | None:
return user
def init_default_project(db: Session, project_cfg: dict, owner_id: int) -> None:
def init_default_project(db: Session, project_cfg: dict, owner_id: int, owner_name: str = "") -> None:
"""Create default project if configured and not exists."""
name = project_cfg.get("name")
if not name:
@@ -83,6 +83,7 @@ def init_default_project(db: Session, project_cfg: dict, owner_id: int) -> None:
project = models.Project(
name=name,
description=project_cfg.get("description", ""),
owner_name=project_cfg.get("owner") or owner_name or "",
owner_id=owner_id,
)
db.add(project)
@@ -108,6 +109,6 @@ def run_init(db: Session) -> None:
# Default project
project_cfg = config.get("default_project")
if project_cfg and admin_user:
init_default_project(db, project_cfg, admin_user.id)
init_default_project(db, project_cfg, admin_user.id, admin_user.username)
logger.info("Initialization complete")