Files
MABEA/backend/app/models/historie.py
T
patrickandClaude Sonnet 5 429ece3c65
CI / backend-tests (push) Failing after 2m34s
CI / frontend-build (push) Successful in 18s
feat(historie): FILE-008 manipulationssicheres Audit-Journal (Hash-Kette je Ressource)
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CVgbozhYmuEhiEJHffRXCV
2026-09-10 11:08:07 +02:00

31 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import uuid
from datetime import datetime
from sqlalchemy import ForeignKey, String
from sqlalchemy.dialects.postgresql import JSONB, TIMESTAMP, UUID
from sqlalchemy.orm import Mapped, mapped_column
from app.db.base import Base
class Historie(Base):
"""Prompt 13: vollständige Audit-Protokollierung ist Sprint 5. Hier bereits
angelegt, weil Sprint 3 (Objekt-Übernahme, Prompt 02.8) einen ersten
Ereignistyp braucht – append-only, kein Update/Delete durch die Anwendung."""
__tablename__ = "historie"
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
erzeugt_von_server_id: Mapped[int] = mapped_column(ForeignKey("systemknoten.id"), nullable=False)
zeitpunkt: Mapped[datetime] = mapped_column(TIMESTAMP(timezone=True), nullable=False)
benutzer_id: Mapped[int | None] = mapped_column(ForeignKey("benutzer.id"))
ereignistyp: Mapped[str] = mapped_column(String, nullable=False)
entitaet_typ: Mapped[str] = mapped_column(String, nullable=False)
entitaet_id: Mapped[str] = mapped_column(String, nullable=False)
alter_wert: Mapped[dict | None] = mapped_column(JSONB)
neuer_wert: Mapped[dict | None] = mapped_column(JSONB)
begruendung: Mapped[str | None] = mapped_column(String)
# FILE-008: SHA-256 über Inhalt+Vorgänger-Hash, Kette läuft je
# (entitaet_typ, entitaet_id) separat - siehe app/services/historie_hash.py.
hash: Mapped[str] = mapped_column(String, nullable=False)