Neue Tabellen hersteller/modell (Migration 0030), CRUD-Endpunkte (/hersteller, /modelle) nach bestehendem Kategorie-Muster, inkl. 409 bei Duplikaten (IntegrityError abgefangen wie in personal.py). geraet_instanz bekommt optionales modell_id-Feld - verknüpft eine konkrete Geräteinstanz (mit Seriennummer, IDENT-004) mit ihrem Hersteller/Modell. Ergänzt Material.hersteller (bleibt unverändert als Freitext) um eine normalisierte Variante gezielt für Geräte mit Seriennummer - keine Datenmigration bestehender Freitext-Werte (Scope dieser Kachel). Bewusst kein neues Admin-UI-Screen für die Pflege (Scope-Grenze der Kachel) - Hersteller/Modell aktuell nur über die API verwaltbar. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CVgbozhYmuEhiEJHffRXCV
106 lines
4.0 KiB
Python
106 lines
4.0 KiB
Python
import enum
|
|
|
|
from sqlalchemy import Boolean, ForeignKey, String, Text, UniqueConstraint
|
|
from sqlalchemy.dialects.postgresql import ENUM as PgEnum
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.db.base import Base
|
|
|
|
|
|
class MaterialTyp(str, enum.Enum):
|
|
standard = "standard"
|
|
ablauf_charge = "ablauf_charge"
|
|
geraet_sn = "geraet_sn"
|
|
|
|
|
|
materialtyp_pg = PgEnum(MaterialTyp, name="materialtyp", create_type=False)
|
|
|
|
|
|
class Bereich(Base):
|
|
__tablename__ = "bereich"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
name: Mapped[str] = mapped_column(String, unique=True, nullable=False)
|
|
beschreibung: Mapped[str | None] = mapped_column(Text)
|
|
|
|
|
|
class Kategorie(Base):
|
|
__tablename__ = "kategorie"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
bereich_id: Mapped[int] = mapped_column(ForeignKey("bereich.id"), nullable=False)
|
|
name: Mapped[str] = mapped_column(String, nullable=False)
|
|
ueberkategorie_id: Mapped[int | None] = mapped_column(ForeignKey("kategorie.id"))
|
|
|
|
|
|
class Standort(Base):
|
|
__tablename__ = "standort"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
name: Mapped[str] = mapped_column(String, unique=True, nullable=False)
|
|
adresse: Mapped[str | None] = mapped_column(Text)
|
|
|
|
|
|
class Objekttyp(Base):
|
|
__tablename__ = "objekttyp"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
bereich_id: Mapped[int] = mapped_column(ForeignKey("bereich.id"), nullable=False)
|
|
kategorie_id: Mapped[int | None] = mapped_column(ForeignKey("kategorie.id"))
|
|
name: Mapped[str] = mapped_column(String, nullable=False)
|
|
# Karte 11 Nachtrag: nur Objekte dieses Typs dürfen als Fahrzeug (Objekt.
|
|
# fahrzeug_id) zugeordnet werden - grenzt die Fahrzeug-Dropdowns serverseitig
|
|
# ein, ohne einen eigenen Fahrzeug-Objekttyp fachlich zu erzwingen.
|
|
ist_zugfahrzeug: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
|
|
|
|
|
class Fach(Base):
|
|
"""Nutzer-Vorgabe: feste Fächer-Liste je Objekttyp, damit beim Anlegen einer
|
|
Vorlagenposition nicht jedes Mal Freitext getippt werden muss. `sortierung`
|
|
steuert die Anzeigereihenfolge (z. B. von oben nach unten im Rucksack)."""
|
|
|
|
__tablename__ = "fach"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
objekttyp_id: Mapped[int] = mapped_column(ForeignKey("objekttyp.id"), nullable=False)
|
|
name: Mapped[str] = mapped_column(String, nullable=False)
|
|
sortierung: Mapped[int] = mapped_column(default=0)
|
|
|
|
|
|
class Hersteller(Base):
|
|
"""IDENT-005: normalisierte Hersteller-Stammdaten statt Freitext - macht
|
|
Geräte/Fahrzeuge herstellerübergreifend auswertbar/filterbar (z.B. "alle
|
|
Weinmann-Geräte prüfpflichtig"). Ergänzt Material.hersteller (Freitext,
|
|
bleibt unverändert), betrifft hier gezielt Geräteinstanzen mit
|
|
Seriennummer (IDENT-004)."""
|
|
|
|
__tablename__ = "hersteller"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
name: Mapped[str] = mapped_column(String, unique=True, nullable=False)
|
|
|
|
|
|
class Modell(Base):
|
|
__tablename__ = "modell"
|
|
__table_args__ = (UniqueConstraint("hersteller_id", "name"),)
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
hersteller_id: Mapped[int] = mapped_column(ForeignKey("hersteller.id"), nullable=False)
|
|
name: Mapped[str] = mapped_column(String, nullable=False)
|
|
|
|
|
|
class Material(Base):
|
|
__tablename__ = "material"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
name: Mapped[str] = mapped_column(String, nullable=False)
|
|
artikelnummer: Mapped[str | None] = mapped_column(String)
|
|
einheit: Mapped[str] = mapped_column(String, nullable=False)
|
|
materialtyp: Mapped[MaterialTyp] = mapped_column(materialtyp_pg, nullable=False)
|
|
kategorie_id: Mapped[int | None] = mapped_column(ForeignKey("kategorie.id"))
|
|
hersteller: Mapped[str | None] = mapped_column(String)
|
|
beschreibung: Mapped[str | None] = mapped_column(Text)
|
|
code: Mapped[str | None] = mapped_column(String, unique=True)
|
|
warnzeitraum_tage: Mapped[int | None] = mapped_column()
|
|
aktiv: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
|