nex_docus/backend/app/models/user.py

30 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"""
用户模型
"""
from sqlalchemy import Column, BigInteger, String, Integer, DateTime, SmallInteger
from sqlalchemy.sql import func
from app.core.database import Base
class User(Base):
"""用户表模型"""
__tablename__ = "users"
id = Column(BigInteger, primary_key=True, autoincrement=True, comment="用户ID")
username = Column(String(50), nullable=False, unique=True, index=True, comment="用户名")
password_hash = Column(String(255), nullable=False, comment="密码哈希")
nickname = Column(String(50), comment="昵称")
email = Column(String(100), index=True, comment="邮箱")
phone = Column(String(20), comment="手机号")
avatar = Column(String(255), comment="头像URL")
status = Column(SmallInteger, default=1, index=True, comment="状态0-禁用 1-启用")
is_superuser = Column(SmallInteger, default=0, comment="是否超级管理员0-否 1-是")
last_login_at = Column(DateTime, comment="最后登录时间")
last_login_ip = Column(String(50), comment="最后登录IP")
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), comment="更新时间")
def __repr__(self):
return f"<User(id={self.id}, username='{self.username}')>"