Spaces:
Sleeping
Sleeping
File size: 921 Bytes
4a665c4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | from sqlalchemy import String, DateTime, ForeignKey, func
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.db.base import Base
class ApiKey(Base):
__tablename__ = "api_keys"
id: Mapped[int] = mapped_column(primary_key=True)
user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"), index=True, nullable=False)
key_hash: Mapped[str] = mapped_column(String(255), unique=True, index=True, nullable=False)
name: Mapped[str] = mapped_column(String(200), nullable=False)
created_at: Mapped[DateTime] = mapped_column(DateTime(timezone=True), server_default=func.now(), nullable=False)
last_used_at: Mapped[DateTime | None] = mapped_column(DateTime(timezone=True), nullable=True)
expires_at: Mapped[DateTime | None] = mapped_column(DateTime(timezone=True), nullable=True)
user = relationship("User", back_populates="api_keys")
|