
- Add username field to User model - Update authentication endpoints to use username instead of email - Create migration for adding username column to user table - Update user services to handle username validation and uniqueness - Maintain email for compatibility, but make username the primary identifier
21 lines
876 B
Python
21 lines
876 B
Python
from datetime import datetime
|
|
from sqlalchemy import Boolean, Column, String, DateTime
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.db.base_class import Base
|
|
|
|
|
|
class User(Base):
|
|
id = Column(String, primary_key=True, index=True)
|
|
username = Column(String, unique=True, index=True)
|
|
email = Column(String, unique=True, index=True)
|
|
hashed_password = Column(String)
|
|
full_name = Column(String, index=True)
|
|
is_active = Column(Boolean, default=True)
|
|
is_superuser = Column(Boolean, default=False)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
# Relationships
|
|
orders = relationship("Order", back_populates="user", cascade="all, delete-orphan")
|
|
cart = relationship("Cart", back_populates="user", uselist=False, cascade="all, delete-orphan") |