user.py 1.3 KB

123456789101112131415161718192021222324252627
  1. """
  2. 用户模型
  3. """
  4. from datetime import datetime
  5. from sqlalchemy import Column, Integer, String, DateTime, Boolean, Text, Date
  6. from app.database import Base
  7. from app.utils.timezone import beijing_now_naive
  8. class User(Base):
  9. """用户表"""
  10. __tablename__ = "users"
  11. id = Column(Integer, primary_key=True, autoincrement=True, comment="主键ID")
  12. username = Column(String(100), unique=True, nullable=False, comment="用户名")
  13. password = Column(String(255), nullable=False, comment="密码(bcrypt加密)")
  14. email = Column(String(255), nullable=True, comment="邮箱")
  15. machine_code = Column(String(255), nullable=True, comment="机器码(MD5)")
  16. card_id = Column(Integer, nullable=True, comment="当前卡密ID")
  17. expire_time = Column(DateTime, nullable=True, comment="到期时间")
  18. status = Column(Boolean, default=True, comment="状态: 1-正常, 0-禁用")
  19. is_deleted = Column(Boolean, default=False, comment="是否删除: 0-否, 1-是")
  20. created_at = Column(DateTime, default=beijing_now_naive, comment="创建时间")
  21. updated_at = Column(DateTime, default=beijing_now_naive, onupdate=beijing_now_naive, comment="更新时间")
  22. def __repr__(self):
  23. return f"<User(id={self.id}, username='{self.username}')>"