Spaces:
Sleeping
Sleeping
| """ | |
| User ORM Model. | |
| Handles user accounts with secure password storage and profile metadata. | |
| """ | |
| from __future__ import annotations | |
| from datetime import datetime | |
| from sqlalchemy import Boolean, DateTime, Integer, String, Text, func | |
| from sqlalchemy.orm import Mapped, mapped_column, relationship | |
| from app.database import Base | |
| class User(Base): | |
| __tablename__ = "users" | |
| id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) | |
| email: Mapped[str] = mapped_column(String(255), unique=True, nullable=False, index=True) | |
| username: Mapped[str] = mapped_column(String(100), unique=True, nullable=False, index=True) | |
| hashed_password: Mapped[str] = mapped_column(String(255), nullable=False) | |
| full_name: Mapped[str] = mapped_column(String(255), nullable=True) | |
| bio: Mapped[str] = mapped_column(Text, nullable=True) | |
| is_active: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False) | |
| is_admin: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False) | |
| created_at: Mapped[datetime] = mapped_column( | |
| DateTime(timezone=True), server_default=func.now(), nullable=False | |
| ) | |
| updated_at: Mapped[datetime] = mapped_column( | |
| DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False | |
| ) | |
| # Relationships | |
| strategies = relationship("Strategy", back_populates="user", lazy="selectin") | |
| portfolios = relationship("Portfolio", back_populates="user", lazy="selectin") | |
| backtest_results = relationship("BacktestResult", back_populates="user", lazy="selectin") | |
| marketplace_entries = relationship("MarketplaceEntry", back_populates="user", lazy="selectin") | |
| research_reports = relationship("ResearchReport", back_populates="user", lazy="selectin") | |
| holdings = relationship("Holding", back_populates="user", lazy="selectin") | |
| chat_sessions = relationship("ChatSession", back_populates="user", lazy="noload") | |
| def __repr__(self) -> str: | |
| return f"<User(id={self.id}, username='{self.username}')>" | |