api_key.py 771 B

1234567891011121314151617
  1. from datetime import datetime
  2. from core_db import AuditMixin, Base, EntityMixin
  3. from sqlalchemy import DateTime, String, Text
  4. from sqlalchemy.orm import Mapped, mapped_column
  5. class ApiKey(EntityMixin, AuditMixin, Base):
  6. __tablename__ = "api_key"
  7. name: Mapped[str] = mapped_column(String(128))
  8. key_prefix: Mapped[str] = mapped_column(String(16), index=True)
  9. key_hash: Mapped[str] = mapped_column(String(128), unique=True, index=True)
  10. status: Mapped[str] = mapped_column(String(32), default="active", index=True)
  11. scopes: Mapped[str | None] = mapped_column(Text, nullable=True)
  12. expires_time: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
  13. last_used_time: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)