16 lines
786 B
Python
16 lines
786 B
Python
from sqlalchemy import Column, Integer, String, DateTime, JSON, ForeignKey, text
|
|
from sqlalchemy.sql import func
|
|
from app.db.base_class import Base
|
|
|
|
class AuditLog(Base):
|
|
__tablename__ = "audit_logs"
|
|
__table_args__ = {"schema": "data"}
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
user_id = Column(Integer, ForeignKey("data.users.id", ondelete="SET NULL"), nullable=True)
|
|
action = Column(String(100), nullable=False) # pl. "LOGIN", "REGISTER", "DELETE_ASSET"
|
|
resource_type = Column(String(50)) # pl. "User", "Asset", "Organization"
|
|
resource_id = Column(String(100))
|
|
details = Column(JSON, server_default=text("'{}'::jsonb"))
|
|
ip_address = Column(String(45))
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now()) |