30 lines
1.3 KiB
Python
30 lines
1.3 KiB
Python
"""
|
||
用户模型
|
||
"""
|
||
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}')>"
|