| from __future__ import annotations |
|
|
| from datetime import datetime |
|
|
| from sqlalchemy import Boolean, DateTime, Float, ForeignKey, Integer, String, func |
| from sqlalchemy.orm import Mapped, mapped_column |
|
|
| from app.core.database import Base |
| from app.utils.ids import prefixed_id |
|
|
|
|
| class ProviderUsageLog(Base): |
| __tablename__ = "provider_usage_logs" |
|
|
| id: Mapped[str] = mapped_column( |
| String(40), |
| primary_key=True, |
| default=lambda: prefixed_id("pulog"), |
| ) |
| user_id: Mapped[str | None] = mapped_column( |
| String(40), |
| ForeignKey("users.id"), |
| index=True, |
| nullable=True, |
| ) |
| provider: Mapped[str] = mapped_column(String(80), index=True, nullable=False) |
| task_type: Mapped[str] = mapped_column(String(80), index=True, nullable=False) |
| request_units: Mapped[int] = mapped_column(Integer, default=0, nullable=False) |
| response_units: Mapped[int] = mapped_column(Integer, default=0, nullable=False) |
| estimated_cost_usd: Mapped[float] = mapped_column(Float, default=0, nullable=False) |
| status: Mapped[str] = mapped_column(String(30), index=True, nullable=False) |
| error_code: Mapped[str | None] = mapped_column(String(120), nullable=True) |
| cache_hit: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False) |
| created_at: Mapped[datetime] = mapped_column( |
| DateTime(timezone=True), |
| server_default=func.now(), |
| index=True, |
| nullable=False, |
| ) |
|
|