23 lines
1.1 KiB
Python
23 lines
1.1 KiB
Python
from sqlalchemy import String, Integer, SmallInteger
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from .base import Base, TimestampMixin, MYSQL_TABLE_ARGS
|
|
from .enums import StatusEnum
|
|
|
|
|
|
class User(Base, TimestampMixin):
|
|
__tablename__ = "sys_user"
|
|
__table_args__ = MYSQL_TABLE_ARGS
|
|
|
|
user_id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
username: Mapped[str] = mapped_column(String(50), unique=True, nullable=False)
|
|
display_name: Mapped[str] = mapped_column(String(50), nullable=False)
|
|
email: Mapped[str | None] = mapped_column(String(100), unique=True)
|
|
phone: Mapped[str | None] = mapped_column(String(30), unique=True)
|
|
password_hash: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
avatar: Mapped[str | None] = mapped_column(String(255))
|
|
status: Mapped[int] = mapped_column(Integer, default=StatusEnum.ENABLED, nullable=False)
|
|
# Changed Boolean to SmallInteger for compatibility with existing data (0/1)
|
|
is_deleted: Mapped[int] = mapped_column(SmallInteger, default=0, nullable=False)
|
|
|
|
roles = relationship("UserRole", back_populates="user")
|