mirror of
https://github.com/Rarebuffalo/securelens-backend.git
synced 2026-06-19 07:00:30 +00:00
27 lines
852 B
Python
27 lines
852 B
Python
import uuid
|
|
from datetime import datetime, timezone
|
|
|
|
from sqlalchemy import String, DateTime, ForeignKey
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class ApiKey(Base):
|
|
__tablename__ = "api_keys"
|
|
|
|
id: Mapped[str] = mapped_column(
|
|
String(36), primary_key=True, default=lambda: str(uuid.uuid4())
|
|
)
|
|
user_id: Mapped[str] = mapped_column(
|
|
String(36), ForeignKey("users.id"), index=True
|
|
)
|
|
name: Mapped[str] = mapped_column(String(100))
|
|
key_prefix: Mapped[str] = mapped_column(String(10))
|
|
hashed_key: Mapped[str] = mapped_column(String(255), unique=True, index=True)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)
|
|
)
|
|
|
|
user = relationship("User", back_populates="api_keys")
|