Spaces:
Sleeping
Sleeping
Update backend with high-quality catalog and fixes
Browse files- app/api/seed.py +22 -1
app/api/seed.py
CHANGED
|
@@ -108,16 +108,37 @@ SCRAPED_TO_TARGET_MAP = {
|
|
| 108 |
async def seed_database(clear: bool = False, db: Session = Depends(get_db)):
|
| 109 |
"""Populate database with proper product data, optionally clearing existing data first."""
|
| 110 |
if clear:
|
| 111 |
-
# Clear existing data
|
|
|
|
| 112 |
db.execute(text("DELETE FROM product_images"))
|
| 113 |
db.execute(text("DELETE FROM cart_items"))
|
| 114 |
db.execute(text("DELETE FROM reviews"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
db.execute(text("DELETE FROM products"))
|
| 116 |
db.execute(text("DELETE FROM categories"))
|
| 117 |
db.execute(text("DELETE FROM coupons"))
|
|
|
|
| 118 |
db.execute(text("DELETE FROM users WHERE role = 'ADMIN'"))
|
| 119 |
db.commit()
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
# 0. Create Default Admin if matches criteria
|
| 122 |
admin_email = "admin@vortex.com"
|
| 123 |
admin_user = db.query(User).filter(User.email == admin_email).first()
|
|
|
|
| 108 |
async def seed_database(clear: bool = False, db: Session = Depends(get_db)):
|
| 109 |
"""Populate database with proper product data, optionally clearing existing data first."""
|
| 110 |
if clear:
|
| 111 |
+
# Clear existing data - Comprehensive wipe
|
| 112 |
+
print(">>> [SEED] Clearing ALL data...")
|
| 113 |
db.execute(text("DELETE FROM product_images"))
|
| 114 |
db.execute(text("DELETE FROM cart_items"))
|
| 115 |
db.execute(text("DELETE FROM reviews"))
|
| 116 |
+
db.execute(text("DELETE FROM payment_details")) # Added
|
| 117 |
+
db.execute(text("DELETE FROM payments")) # Added
|
| 118 |
+
db.execute(text("DELETE FROM order_items")) # Added
|
| 119 |
+
db.execute(text("DELETE FROM orders")) # Added
|
| 120 |
+
db.execute(text("DELETE FROM addresses")) # Added
|
| 121 |
db.execute(text("DELETE FROM products"))
|
| 122 |
db.execute(text("DELETE FROM categories"))
|
| 123 |
db.execute(text("DELETE FROM coupons"))
|
| 124 |
+
db.execute(text("DELETE FROM store_settings")) # Clean settings
|
| 125 |
db.execute(text("DELETE FROM users WHERE role = 'ADMIN'"))
|
| 126 |
db.commit()
|
| 127 |
|
| 128 |
+
# 0. Ensure Store Settings exist (even without clear)
|
| 129 |
+
from app.models.settings import StoreSettings
|
| 130 |
+
settings = db.query(StoreSettings).first()
|
| 131 |
+
if not settings:
|
| 132 |
+
print(">>> [SEED] Creating default store settings...")
|
| 133 |
+
settings = StoreSettings(
|
| 134 |
+
store_name="أفق",
|
| 135 |
+
primary_color="#046c4e",
|
| 136 |
+
secondary_color="#d97706",
|
| 137 |
+
logo_url="/logo.png"
|
| 138 |
+
)
|
| 139 |
+
db.add(settings)
|
| 140 |
+
db.commit()
|
| 141 |
+
|
| 142 |
# 0. Create Default Admin if matches criteria
|
| 143 |
admin_email = "admin@vortex.com"
|
| 144 |
admin_user = db.query(User).filter(User.email == admin_email).first()
|