STABLE: Final schema sync, optimized gitignore
This commit is contained in:
@@ -1,51 +1,47 @@
|
||||
# /opt/docker/dev/service_finder/backend/app/models/history.py
|
||||
import uuid
|
||||
import enum
|
||||
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, JSON, Date, Text, Enum
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime, date
|
||||
from typing import Optional, Any
|
||||
from sqlalchemy import String, DateTime, ForeignKey, JSON, Date, Text, Integer
|
||||
from sqlalchemy.dialects.postgresql import ENUM as PG_ENUM, UUID as PG_UUID
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from sqlalchemy.sql import func
|
||||
from sqlalchemy.dialects.postgresql import UUID as PG_UUID
|
||||
from app.db.base_class import Base
|
||||
|
||||
# MB 2.0: Központi aszinkron adatbázis motorból húzzuk be a Base-t
|
||||
from app.database import Base
|
||||
|
||||
class LogSeverity(str, enum.Enum):
|
||||
info = "info" # Általános művelet (pl. profil megtekintés)
|
||||
warning = "warning" # Gyanús, de nem biztosan káros (pl. 3 elrontott jelszó)
|
||||
critical = "critical" # Súlyos művelet (pl. jelszóváltoztatás, export)
|
||||
emergency = "emergency" # Azonnali beavatkozást igényel (pl. SuperAdmin módosítás)
|
||||
info = "info"
|
||||
warning = "warning"
|
||||
critical = "critical"
|
||||
emergency = "emergency"
|
||||
|
||||
class VehicleOwnership(Base):
|
||||
__tablename__ = "vehicle_ownerships"
|
||||
__table_args__ = {"schema": "data"}
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
vehicle_id = Column(PG_UUID(as_uuid=True), ForeignKey("data.assets.id"), nullable=False)
|
||||
user_id = Column(Integer, ForeignKey("data.users.id"), nullable=False)
|
||||
start_date = Column(Date, nullable=False, default=func.current_date())
|
||||
end_date = Column(Date, nullable=True)
|
||||
notes = Column(Text, nullable=True)
|
||||
|
||||
vehicle = relationship("Asset", back_populates="ownership_history")
|
||||
user = relationship("User", back_populates="ownership_history")
|
||||
|
||||
class AuditLog(Base):
|
||||
""" Rendszerszintű műveletnapló. """
|
||||
__tablename__ = "audit_logs"
|
||||
__table_args__ = {"schema": "data"}
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
user_id = Column(Integer, ForeignKey("data.users.id"), nullable=True)
|
||||
severity = Column(Enum(LogSeverity), default=LogSeverity.info, nullable=False)
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
|
||||
|
||||
# Mi történt és min?
|
||||
action = Column(String(100), nullable=False, index=True)
|
||||
target_type = Column(String(50), index=True) # pl. "User", "Wallet", "Asset"
|
||||
target_id = Column(String(50), index=True) # A cél rekord ID-ja
|
||||
# MB 2.0 JAVÍTÁS: A felhasználó az identity sémában lakik!
|
||||
user_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("identity.users.id"))
|
||||
|
||||
# Részletes adatok (JSONB formátum a rugalmasságért)
|
||||
# A 'changes' helyett explicit old/new párost használunk a könnyebb visszaállításhoz
|
||||
old_data = Column(JSON, nullable=True)
|
||||
new_data = Column(JSON, nullable=True)
|
||||
severity: Mapped[LogSeverity] = mapped_column(
|
||||
PG_ENUM(LogSeverity, name="log_severity", schema="data"),
|
||||
default=LogSeverity.info
|
||||
)
|
||||
|
||||
# Biztonsági nyomkövetés
|
||||
ip_address = Column(String(45), index=True) # IPv6-ot is támogat
|
||||
user_agent = Column(Text, nullable=True) # Böngésző/Eszköz információ
|
||||
action: Mapped[str] = mapped_column(String(100), index=True)
|
||||
target_type: Mapped[Optional[str]] = mapped_column(String(50), index=True)
|
||||
target_id: Mapped[Optional[str]] = mapped_column(String(50), index=True)
|
||||
|
||||
timestamp = Column(DateTime(timezone=True), server_default=func.now(), index=True)
|
||||
old_data: Mapped[Optional[Any]] = mapped_column(JSON)
|
||||
new_data: Mapped[Optional[Any]] = mapped_column(JSON)
|
||||
|
||||
user = relationship("User")
|
||||
ip_address: Mapped[Optional[str]] = mapped_column(String(45), index=True)
|
||||
user_agent: Mapped[Optional[Text]] = mapped_column(Text)
|
||||
timestamp: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), index=True)
|
||||
|
||||
user: Mapped[Optional["User"]] = relationship("User")
|
||||
Reference in New Issue
Block a user