refactor: simplify schema names and remove provider id columns

This commit is contained in:
Chris
2026-04-03 01:49:36 +08:00
parent 6e43a3b2c8
commit 1ff0589b29
26 changed files with 170 additions and 179 deletions

View File

@@ -79,7 +79,7 @@ def _flatten_groups(nodes: list[dict], inherited_company_key: str | None = None)
if company_key:
companies[company_key] = {
"company_key": company_key,
"display_name": _first_attr(attrs, "display_name") or name or company_key,
"name": _first_attr(attrs, "name") or _first_attr(attrs, "display_name") or name or company_key,
"status": _first_attr(attrs, "status") or "active",
"provider_group_id": group_id,
}
@@ -146,8 +146,7 @@ def sync_from_provider(db: Session, *, force: bool = False) -> dict[str, int]:
if company is None:
company = companies_repo.create(
company_key=company_key,
display_name=row["display_name"],
legal_name=None,
name=row["name"],
provider_group_id=row["provider_group_id"],
status=row["status"],
)
@@ -155,7 +154,7 @@ def sync_from_provider(db: Session, *, force: bool = False) -> dict[str, int]:
else:
company = companies_repo.update(
company,
display_name=row["display_name"],
name=row["name"],
provider_group_id=row["provider_group_id"],
status=row["status"],
)
@@ -172,8 +171,7 @@ def sync_from_provider(db: Session, *, force: bool = False) -> dict[str, int]:
if placeholder is None:
placeholder = companies_repo.create(
company_key=company_key,
display_name=company_key,
legal_name=None,
name=company_key,
provider_group_id=None,
status="active",
)
@@ -213,7 +211,7 @@ def sync_from_provider(db: Session, *, force: bool = False) -> dict[str, int]:
if client_id in BUILTIN_CLIENT_IDS:
continue
system = db.scalar(select(System).where(System.provider_client_id == client_id))
system = db.scalar(select(System).where(System.name == client_id))
system_name = str(client.get("name", "")).strip() or client_id
system_status = "active" if client.get("enabled", True) else "inactive"
if system is None:
@@ -221,7 +219,6 @@ def sync_from_provider(db: Session, *, force: bool = False) -> dict[str, int]:
system = systems_repo.create(
system_key=system_key,
name=system_name,
provider_client_id=client_id,
status=system_status,
)
systems_created += 1
@@ -246,7 +243,7 @@ def sync_from_provider(db: Session, *, force: bool = False) -> dict[str, int]:
role = db.scalar(
select(Role).where(
Role.system_id == system.id,
Role.provider_role_name == role_name,
Role.name == role_name,
)
)
if role is None:
@@ -256,7 +253,6 @@ def sync_from_provider(db: Session, *, force: bool = False) -> dict[str, int]:
system_id=system.id,
name=role_name,
description=role_desc,
provider_role_name=role_name,
status=role_status,
)
roles_created += 1
@@ -339,7 +335,7 @@ def sync_systems_from_provider(db: Session, *, force: bool = False) -> dict[str,
if client_id in BUILTIN_CLIENT_IDS:
continue
system = db.scalar(select(System).where(System.provider_client_id == client_id))
system = db.scalar(select(System).where(System.name == client_id))
system_name = str(client.get("name", "")).strip() or client_id
system_status = "active" if client.get("enabled", True) else "inactive"
if system is None:
@@ -347,7 +343,6 @@ def sync_systems_from_provider(db: Session, *, force: bool = False) -> dict[str,
system = systems_repo.create(
system_key=system_key,
name=system_name,
provider_client_id=client_id,
status=system_status,
)
systems_created += 1
@@ -371,7 +366,7 @@ def sync_systems_from_provider(db: Session, *, force: bool = False) -> dict[str,
role = db.scalar(
select(Role).where(
Role.system_id == system.id,
Role.provider_role_name == role_name,
Role.name == role_name,
)
)
if role is None:
@@ -381,7 +376,6 @@ def sync_systems_from_provider(db: Session, *, force: bool = False) -> dict[str,
system_id=system.id,
name=role_name,
description=role_desc,
provider_role_name=role_name,
status=role_status,
)
roles_created += 1