30 lines
1020 B
Python
30 lines
1020 B
Python
from typing import TYPE_CHECKING
|
|
|
|
from sqlalchemy import BIGINT, INTEGER, REAL, TEXT, VARCHAR, ForeignKey
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from db.base import Base
|
|
|
|
if TYPE_CHECKING:
|
|
from db.models.sessions import Session
|
|
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id: Mapped[int] = mapped_column(
|
|
INTEGER, unique=True, autoincrement=True, nullable=False, primary_key=True
|
|
)
|
|
username: Mapped[str] = mapped_column(TEXT, unique=True, nullable=True)
|
|
hashed_password: Mapped[str] = mapped_column(VARCHAR(255), nullable=True)
|
|
telegram_id: Mapped[int] = mapped_column(BIGINT, unique=True, nullable=True)
|
|
referal_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=True)
|
|
|
|
balance: Mapped[float] = mapped_column(REAL, nullable=False, default=0)
|
|
|
|
sessions: Mapped[list["Session"]] = relationship(back_populates="user", lazy="selectin")
|
|
referal: Mapped["User | None"] = relationship(
|
|
"User",
|
|
remote_side=[id],
|
|
)
|