Adding audit log

This commit is contained in:
Ian Roddis committed 2026-06-25 11:25:26 -03:00
1 parent fe6f9cca05
commit 45bc5bf8f6
18 files changed
+543 -119

No files matched your search

+2
View File
@@ -1,6 +1,7 @@
"""Import all models so they register with ``Base.metadata``."""
from app.models.associations import role_permissions, user_roles
from app.models.audit_log import AuditLog
from app.models.iso_thread import IsoThread
from app.models.manufacturer import Manufacturer
from app.models.part_type import PartType
@@ -12,6 +13,7 @@ from app.models.unc_thread import UncThread
from app.models.user import User
__all__ = [
"AuditLog",
"IsoThread",
"Manufacturer",
"PartType",
+23
View File
@@ -0,0 +1,23 @@
from datetime import datetime
from sqlalchemy import DateTime, ForeignKey, String, func
from sqlalchemy.orm import Mapped, mapped_column
from app.core.database import Base
class AuditLog(Base):
__tablename__ = "audit_logs"
id: Mapped[int] = mapped_column(primary_key=True)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), index=True
)
user_id: Mapped[int | None] = mapped_column(
ForeignKey("users.id", ondelete="SET NULL"), nullable=True, index=True
)
user_email: Mapped[str] = mapped_column(String(255), nullable=False)
action: Mapped[str] = mapped_column(String(16), nullable=False)
resource_type: Mapped[str] = mapped_column(String(64), nullable=False)
resource_id: Mapped[int | None] = mapped_column(nullable=True)
description: Mapped[str] = mapped_column(nullable=False)