44 lines
1.7 KiB
Python
44 lines
1.7 KiB
Python
from datetime import date, datetime
|
|
|
|
from sqlalchemy import Date, DateTime, Integer, JSON, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.db import Base
|
|
|
|
|
|
class AuditLog(Base):
|
|
__tablename__ = "audit_logs"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
actor_id: Mapped[int | None] = mapped_column(index=True)
|
|
action: Mapped[str] = mapped_column(String(120), index=True)
|
|
target_type: Mapped[str | None] = mapped_column(String(80), index=True)
|
|
target_id: Mapped[str | None] = mapped_column(String(80))
|
|
ip: Mapped[str | None] = mapped_column(String(80))
|
|
user_agent: Mapped[str | None] = mapped_column(String(255))
|
|
detail_json: Mapped[dict | None] = mapped_column(JSON)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, index=True)
|
|
|
|
|
|
class ApiCallLog(Base):
|
|
__tablename__ = "api_call_logs"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
provider: Mapped[str] = mapped_column(String(80), index=True)
|
|
endpoint: Mapped[str] = mapped_column(String(180))
|
|
status: Mapped[str] = mapped_column(String(30), index=True)
|
|
latency_ms: Mapped[int | None] = mapped_column(Integer)
|
|
request_id: Mapped[str | None] = mapped_column(String(120))
|
|
error_message: Mapped[str | None] = mapped_column(Text)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
|
|
|
|
|
class UsageDaily(Base):
|
|
__tablename__ = "usage_daily"
|
|
|
|
stat_date: Mapped[date] = mapped_column(Date, primary_key=True)
|
|
question_count: Mapped[int] = mapped_column(Integer, default=0)
|
|
user_count: Mapped[int] = mapped_column(Integer, default=0)
|
|
token_usage: Mapped[int] = mapped_column(Integer, default=0)
|
|
pu_usage: Mapped[int] = mapped_column(Integer, default=0)
|