25 lines
980 B
Python
25 lines
980 B
Python
from datetime import datetime
|
|
|
|
from sqlalchemy import DateTime, ForeignKey, Integer, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class AuditLog(Base):
|
|
__tablename__ = "audit_logs"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
|
user_id: Mapped[int | None] = mapped_column(
|
|
ForeignKey("users.id", ondelete="SET NULL"), nullable=True
|
|
)
|
|
username: Mapped[str | None] = mapped_column(String(100), nullable=True)
|
|
action: Mapped[str] = mapped_column(String(100), index=True)
|
|
resource_type: Mapped[str | None] = mapped_column(String(50), nullable=True)
|
|
resource_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
details: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
ip_address: Mapped[str | None] = mapped_column(String(45), nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime, default=datetime.utcnow, index=True
|
|
)
|