Sprint 0: FastAPI-Skeleton, vollständiges DB-Schema (Alembic), Auth (JWT/bcrypt), Rollen-Dependency, CI
CI / backend-tests (push) Failing after 1s
CI / backend-tests (push) Failing after 1s
- Vollständiges Ziel-Schema aus Prompt 20 als initiale Migration (inkl. Karte-13-Vorbereitung: UUID-PKs, systemknoten) - Seed-Migration für Hauptserver-Datensatz (Sprintplan E6) - JWT-Login + /auth/me, require_roles-Dependency (Prompt 05 Berechtigungsmatrix) - Tests: health, login/me, Rollen-Ablehnung/-Zulassung (S0-Abnahmekriterien) - Gitea-Actions-CI: install -> migrate -> pytest mit Coverage-Gate 50% Nur Code/Config erzeugt, nicht lokal installiert oder ausgeführt (Deployment-Regel). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L85hmKbvX7Cqkq47KnQhFt
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import enum
|
||||
|
||||
from sqlalchemy import Boolean, ForeignKey, String
|
||||
from sqlalchemy.dialects.postgresql import ENUM as PgEnum
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.db.base import Base
|
||||
|
||||
|
||||
class KnotenTyp(str, enum.Enum):
|
||||
haupt = "haupt"
|
||||
satellit = "satellit"
|
||||
|
||||
|
||||
class RolleTyp(str, enum.Enum):
|
||||
mitarbeiter = "mitarbeiter"
|
||||
materialverantwortlicher = "materialverantwortlicher"
|
||||
leitungsverantwortlicher = "leitungsverantwortlicher"
|
||||
administration = "administration"
|
||||
|
||||
|
||||
# create_type=False: die PostgreSQL-ENUM-Typen werden ausschließlich per Alembic-Migration
|
||||
# angelegt (0001_initial_schema), damit Migration und ORM-Modell nicht auseinanderlaufen.
|
||||
knoten_typ_pg = PgEnum(KnotenTyp, name="knoten_typ", create_type=False)
|
||||
rolle_typ_pg = PgEnum(RolleTyp, name="rolle_typ", create_type=False)
|
||||
|
||||
|
||||
class Systemknoten(Base):
|
||||
"""Hauptserver oder Satellit (Karte 13). V1 nutzt ausschließlich den Hauptserver-Datensatz."""
|
||||
|
||||
__tablename__ = "systemknoten"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
name: Mapped[str] = mapped_column(String, unique=True, nullable=False)
|
||||
typ: Mapped[KnotenTyp] = mapped_column(knoten_typ_pg, nullable=False, default=KnotenTyp.satellit)
|
||||
|
||||
|
||||
class Benutzer(Base):
|
||||
__tablename__ = "benutzer"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
name: Mapped[str] = mapped_column(String, nullable=False)
|
||||
login: Mapped[str] = mapped_column(String, unique=True, nullable=False)
|
||||
passwort_hash: Mapped[str] = mapped_column(String, nullable=False)
|
||||
aktiv: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
|
||||
|
||||
rollen: Mapped[list["BenutzerRolle"]] = relationship(back_populates="benutzer", lazy="selectin")
|
||||
|
||||
@property
|
||||
def rollen_namen(self) -> list[str]:
|
||||
return [r.rolle.value for r in self.rollen]
|
||||
|
||||
|
||||
class BenutzerRolle(Base):
|
||||
__tablename__ = "benutzer_rolle"
|
||||
|
||||
benutzer_id: Mapped[int] = mapped_column(ForeignKey("benutzer.id"), primary_key=True)
|
||||
rolle: Mapped[RolleTyp] = mapped_column(rolle_typ_pg, primary_key=True)
|
||||
|
||||
benutzer: Mapped["Benutzer"] = relationship(back_populates="rollen")
|
||||
Reference in New Issue
Block a user