swag-shop/backend/app/models/user_model.py

33 lines
1.5 KiB
Python

from sqlalchemy import Column, String, Integer, ForeignKey, TIMESTAMP
from sqlalchemy.dialects.mysql import INTEGER
from sqlalchemy.orm import relationship
from .base_model import Base
class User(Base):
__tablename__ = 'user'
id = Column(INTEGER(unsigned=True), primary_key=True, autoincrement=True)
user_role_id = Column(INTEGER(unsigned=True), ForeignKey('user_role.id'), nullable=False)
shop_id = Column(Integer, ForeignKey('shop.id'), nullable=True)
username = Column(String(64), nullable=False, unique=True)
email = Column(String(128), nullable=False, unique=True)
password = Column(String(60), nullable=False)
first_name = Column(String(64), nullable=True)
last_name = Column(String(64), nullable=True)
phone_number = Column(String(15), nullable=False)
profile_picture = Column(String(100), nullable=True)
created_at = Column(TIMESTAMP, nullable=False, server_default="CURRENT_TIMESTAMP")
updated_at = Column(TIMESTAMP, nullable=False, server_default="CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
last_login = Column(TIMESTAMP, nullable=True, server_default="CURRENT_TIMESTAMP")
owned_shops = relationship("Shop", back_populates="owner")
registered_shop = relationship("Shop", back_populates="registered_users")
role = relationship("UserRole", back_populates="users")
preferences = relationship("UserPreferences", uselist=False, back_populates="user")
statistics = relationship("UserStatistics", uselist=False, back_populates="user_statistics")
__all__ = ["User"]