33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
"""User SQLAlchemy model."""
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from sqlalchemy import DateTime, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.db.database import Base
|
|
|
|
|
|
class User(Base):
|
|
"""User model for authentication and profile information."""
|
|
|
|
__tablename__ = "users"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
username: Mapped[str] = mapped_column(String(50), unique=True, nullable=False)
|
|
email: Mapped[str] = mapped_column(String(255), unique=True, nullable=False)
|
|
password_hash: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
avatar_url: Mapped[Optional[str]] = mapped_column(
|
|
String(500), default="/static/default-avatar.png"
|
|
)
|
|
bio: Mapped[Optional[str]] = mapped_column(Text, default="")
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True),
|
|
server_default=func.now(),
|
|
nullable=False,
|
|
)
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<User(id={self.id}, username='{self.username}')>"
|