34 lines
1.3 KiB
Python
34 lines
1.3 KiB
Python
|
|
from datetime import datetime
|
||
|
|
from sqlalchemy import String, BigInteger, DateTime
|
||
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||
|
|
|
||
|
|
from app.core.database import Base
|
||
|
|
|
||
|
|
|
||
|
|
class User(Base):
|
||
|
|
__tablename__ = "users"
|
||
|
|
|
||
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
||
|
|
login: Mapped[str] = mapped_column(String(50), unique=True, nullable=False, index=True)
|
||
|
|
password_hash: Mapped[str] = mapped_column(String(255), nullable=False)
|
||
|
|
nickname: Mapped[str] = mapped_column(String(50), nullable=False)
|
||
|
|
avatar_path: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
||
|
|
telegram_id: Mapped[int | None] = mapped_column(BigInteger, unique=True, nullable=True)
|
||
|
|
telegram_username: Mapped[str | None] = mapped_column(String(50), nullable=True)
|
||
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||
|
|
|
||
|
|
# Relationships
|
||
|
|
organized_marathons: Mapped[list["Marathon"]] = relationship(
|
||
|
|
"Marathon",
|
||
|
|
back_populates="organizer",
|
||
|
|
foreign_keys="Marathon.organizer_id"
|
||
|
|
)
|
||
|
|
participations: Mapped[list["Participant"]] = relationship(
|
||
|
|
"Participant",
|
||
|
|
back_populates="user"
|
||
|
|
)
|
||
|
|
added_games: Mapped[list["Game"]] = relationship(
|
||
|
|
"Game",
|
||
|
|
back_populates="added_by_user"
|
||
|
|
)
|