26 lines
817 B
Python
26 lines
817 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=False, index=True)
|
||
|
|
hashed_password = Column(String(255), nullable=False)
|
||
|
|
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}')>"
|