40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
"""
|
|
Script to purge old dummy mock products and keep only the 40 high-quality Cashify refurbished gadgets.
|
|
"""
|
|
import app.models.db_base
|
|
from app.core.database.db_session import SessionLocal
|
|
from app.models.ProductModel import Product, ProductVariant, ProductImage
|
|
from app.models.CategoryModel import Category
|
|
from app.core.database.cache_manager import cache
|
|
|
|
db = SessionLocal()
|
|
|
|
# Archive all old dummy mock products (starting with 'Premium ')
|
|
dummy_prods = db.query(Product).filter(Product.name.like("Premium %")).all()
|
|
dummy_count = len(dummy_prods)
|
|
|
|
for p in dummy_prods:
|
|
p.status = "archived"
|
|
|
|
db.commit()
|
|
|
|
# Ensure all 40 Cashify products have status 'active' and accurate categories
|
|
active_prods = db.query(Product).filter(Product.name.like("Refurbished %")).all()
|
|
for p in active_prods:
|
|
p.status = "active"
|
|
|
|
db.commit()
|
|
|
|
# Clear cache
|
|
cache.clear()
|
|
|
|
remaining_count = db.query(Product).count()
|
|
print(f"Purged {dummy_count} old dummy mock products. Total active catalog size: {remaining_count}")
|
|
|
|
# Print categories and product counts
|
|
cats = db.query(Category).all()
|
|
for c in cats:
|
|
count = db.query(Product).filter(Product.category_id == c.category_id, Product.status == 'active').count()
|
|
print(f"Category: {c.name} ({c.slug}) -> {count} active products")
|
|
|
|
db.close()
|