Added marketplace support

This commit is contained in:
2025-09-05 22:14:52 +02:00
parent 9dd177bddc
commit 4fb67e594d
6 changed files with 1307 additions and 117 deletions

View File

@@ -1,4 +1,4 @@
# models/database_models.py
# models/database_models.py - Updated with Marketplace Support
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Index, UniqueConstraint, Boolean
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
@@ -65,6 +65,11 @@ class Product(Base):
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)
@@ -72,8 +77,14 @@ class Product(Base):
stock_entries = relationship("Stock", foreign_keys="Stock.gtin", primaryjoin="Product.gtin == Stock.gtin",
viewonly=True)
# 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}')>"
return f"<Product(product_id='{self.product_id}', title='{self.title}', marketplace='{self.marketplace}', shop='{self.shop_name}')>"
class Stock(Base):
@@ -96,13 +107,15 @@ class Stock(Base):
return f"<Stock(gtin='{self.gtin}', location='{self.location}', quantity={self.quantity})>"
class ImportJob(Base):
__tablename__ = "import_jobs"
class MarketplaceImportJob(Base):
__tablename__ = "marketplace_import_jobs"
id = Column(Integer, primary_key=True, index=True)
status = Column(String, nullable=False,
default="pending") # pending, processing, completed, failed, completed_with_errors
source_url = Column(String, nullable=False)
marketplace = Column(String, nullable=False, index=True, default="Letzshop") # Index for marketplace filtering
shop_name = Column(String, nullable=False, index=True) # Index for shop filtering
user_id = Column(Integer, ForeignKey('users.id')) # Foreign key to users table
imported_count = Column(Integer, default=0)
updated_count = Column(Integer, default=0)
@@ -116,5 +129,11 @@ class ImportJob(Base):
# Relationship to user
user = relationship("User", foreign_keys=[user_id])
# Additional indexes for marketplace import job queries
__table_args__ = (
Index('idx_marketplace_import_user_marketplace', 'user_id', 'marketplace'), # User's marketplace imports
Index('idx_marketplace_import_shop_status', 'shop_name', 'status'), # Shop import status
)
def __repr__(self):
return f"<ImportJob(id={self.id}, status='{self.status}', imported={self.imported_count})>"
return f"<MarketplaceImportJob(id={self.id}, marketplace='{self.marketplace}', shop='{self.shop_name}', status='{self.status}', imported={self.imported_count})>"