marketplace refactoring
This commit is contained in:
@@ -1,87 +0,0 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import (Boolean, Column, DateTime, Float, ForeignKey, Index,
|
||||
Integer, String, Text, UniqueConstraint)
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
# Import Base from the central database module instead of creating a new one
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class Product(Base):
|
||||
__tablename__ = "products"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
product_id = Column(String, unique=True, index=True, nullable=False)
|
||||
title = Column(String, nullable=False)
|
||||
description = Column(String)
|
||||
link = Column(String)
|
||||
image_link = Column(String)
|
||||
availability = Column(String, index=True) # Index for filtering
|
||||
price = Column(String)
|
||||
brand = Column(String, index=True) # Index for filtering
|
||||
gtin = Column(String, index=True) # Index for stock lookups
|
||||
mpn = Column(String)
|
||||
condition = Column(String)
|
||||
adult = Column(String)
|
||||
multipack = Column(Integer)
|
||||
is_bundle = Column(String)
|
||||
age_group = Column(String)
|
||||
color = Column(String)
|
||||
gender = Column(String)
|
||||
material = Column(String)
|
||||
pattern = Column(String)
|
||||
size = Column(String)
|
||||
size_type = Column(String)
|
||||
size_system = Column(String)
|
||||
item_group_id = Column(String)
|
||||
google_product_category = Column(String, index=True) # Index for filtering
|
||||
product_type = Column(String)
|
||||
custom_label_0 = Column(String)
|
||||
custom_label_1 = Column(String)
|
||||
custom_label_2 = Column(String)
|
||||
custom_label_3 = Column(String)
|
||||
custom_label_4 = Column(String)
|
||||
additional_image_link = Column(String)
|
||||
sale_price = Column(String)
|
||||
unit_pricing_measure = Column(String)
|
||||
unit_pricing_base_measure = Column(String)
|
||||
identifier_exists = Column(String)
|
||||
shipping = Column(String)
|
||||
currency = Column(String)
|
||||
|
||||
# New marketplace fields
|
||||
marketplace = Column(
|
||||
String, index=True, nullable=True, default="Letzshop"
|
||||
) # Index for marketplace filtering
|
||||
shop_name = Column(String, index=True, nullable=True) # Index for shop filtering
|
||||
|
||||
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
updated_at = Column(
|
||||
DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False
|
||||
)
|
||||
|
||||
# Relationship to stock (one-to-many via GTIN)
|
||||
stock_entries = relationship(
|
||||
"Stock",
|
||||
foreign_keys="Stock.gtin",
|
||||
primaryjoin="Product.gtin == Stock.gtin",
|
||||
viewonly=True,
|
||||
)
|
||||
shop_products = relationship("ShopProduct", back_populates="product")
|
||||
|
||||
# Additional indexes for marketplace queries
|
||||
__table_args__ = (
|
||||
Index(
|
||||
"idx_marketplace_shop", "marketplace", "shop_name"
|
||||
), # Composite index for marketplace+shop queries
|
||||
Index(
|
||||
"idx_marketplace_brand", "marketplace", "brand"
|
||||
), # Composite index for marketplace+brand queries
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return (
|
||||
f"<Product(product_id='{self.product_id}', title='{self.title}', marketplace='{self.marketplace}', "
|
||||
f"shop='{self.shop_name}')>"
|
||||
)
|
||||
Reference in New Issue
Block a user