"""ApiToken model for OpenRouter API Key Monitor. T10: ApiToken SQLAlchemy model """ from datetime import datetime from sqlalchemy import Column, Integer, String, DateTime, Boolean, ForeignKey from sqlalchemy.orm import relationship from openrouter_monitor.database import Base class ApiToken(Base): """API Token model for public API access. Attributes: id: Primary key user_id: Foreign key to users table token_hash: SHA-256 hash of the token (not the token itself) name: Human-readable name for the token created_at: Timestamp when token was created last_used_at: Timestamp when token was last used is_active: Whether the token is active user: Relationship to user """ __tablename__ = "api_tokens" id = Column(Integer, primary_key=True, index=True) user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True) token_hash = Column(String(255), nullable=False, index=True) name = Column(String(100), nullable=False) created_at = Column(DateTime, default=datetime.utcnow) last_used_at = Column(DateTime, nullable=True) is_active = Column(Boolean, default=True, index=True) # Relationships user = relationship("User", back_populates="api_tokens", lazy="selectin")