mirror of
https://github.com/rommapp/romm.git
synced 2026-04-23 06:54:40 +00:00
d97791f1d4
- Add back_populates="client_tokens" to ClientToken.user relationship - Fix rate limit race condition: increment-first pattern instead of read-then-write - Remove unused User import from tests - Add i18n keys to all non-en_US locales
28 lines
1018 B
Python
28 lines
1018 B
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from typing import TYPE_CHECKING
|
|
|
|
from sqlalchemy import TIMESTAMP, ForeignKey, String
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from models.base import BaseModel
|
|
|
|
if TYPE_CHECKING:
|
|
from models.user import User
|
|
|
|
|
|
class ClientToken(BaseModel):
|
|
__tablename__ = "client_tokens"
|
|
__table_args__ = {"extend_existing": True}
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"))
|
|
name: Mapped[str] = mapped_column(String(255))
|
|
hashed_token: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
|
scopes: Mapped[str] = mapped_column(String(1000))
|
|
expires_at: Mapped[datetime | None] = mapped_column(TIMESTAMP(timezone=True))
|
|
last_used_at: Mapped[datetime | None] = mapped_column(TIMESTAMP(timezone=True))
|
|
|
|
user: Mapped[User] = relationship(lazy="joined", back_populates="client_tokens")
|