29 lines
994 B
Python
29 lines
994 B
Python
"""User ORM model."""
|
|
|
|
import uuid
|
|
|
|
from sqlalchemy import Boolean, Column, DateTime, String
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
from .base import Base
|
|
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
|
username = Column(String(50), unique=True, nullable=False, index=True)
|
|
email = Column(String(255), unique=True, nullable=True, index=True)
|
|
hashed_password = Column(String(255), nullable=True)
|
|
wx_openid = Column(String(64), unique=True, nullable=True, index=True)
|
|
wx_nickname = Column(String(100), nullable=True)
|
|
wx_avatar = Column(String(500), nullable=True)
|
|
created_at = Column(DateTime, server_default=func.now())
|
|
is_active = Column(Boolean, default=True)
|
|
|
|
accounts = relationship("Account", back_populates="user", cascade="all, delete-orphan")
|
|
|
|
def __repr__(self):
|
|
return f"<User(id={self.id}, username='{self.username}')>"
|