21 lines
891 B
Python
21 lines
891 B
Python
"""审计日志 ORM 模型。"""
|
|
import uuid
|
|
from datetime import datetime
|
|
from sqlalchemy import String, DateTime, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class AuditLog(Base):
|
|
__tablename__ = "audit_logs"
|
|
|
|
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
|
user_id: Mapped[str] = mapped_column(String(36), nullable=False, index=True)
|
|
username: Mapped[str] = mapped_column(String(50), nullable=False)
|
|
action: Mapped[str] = mapped_column(String(100), nullable=False, index=True)
|
|
target: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
detail: 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)
|