shop product refactoring

This commit is contained in:
2025-10-04 23:38:53 +02:00
parent 4d2866af5e
commit 0114b6c46e
68 changed files with 2234 additions and 2236 deletions

View File

@@ -8,11 +8,11 @@ from sqlalchemy.orm import relationship
from app.core.database import Base
from models.database.base import TimestampMixin
class Product(Base):
class Product(Base, TimestampMixin):
__tablename__ = "products"
id = Column(Integer, primary_key=True, index=True)
shop_id = Column(Integer, ForeignKey("shops.id"), nullable=False)
vendor_id = Column(Integer, ForeignKey("vendors.id"), nullable=False)
marketplace_product_id = Column(Integer, ForeignKey("marketplace_products.id"), nullable=False)
# Shop-specific overrides (can override the main product data)
@@ -32,17 +32,13 @@ class Product(Base):
min_quantity = Column(Integer, default=1)
max_quantity = Column(Integer)
# Timestamps
created_at = Column(DateTime, default=datetime.utcnow)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
# Relationships
shop = relationship("Shop", back_populates="product")
vendor = relationship("Vendor", back_populates="product")
marketplace_product = relationship("MarketplaceProduct", back_populates="product")
# Constraints
__table_args__ = (
UniqueConstraint("shop_id", "marketplace_product_id", name="uq_product"),
Index("idx_product_active", "shop_id", "is_active"),
Index("idx_product_featured", "shop_id", "is_featured"),
UniqueConstraint("vendor_id", "marketplace_product_id", name="uq_product"),
Index("idx_product_active", "vendor_id", "is_active"),
Index("idx_product_featured", "vendor_id", "is_featured"),
)