184 lines
6.8 KiB
Python
184 lines
6.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Insert sample products into the database using SQLAlchemy ORM
|
|
"""
|
|
from app.database.database import SessionLocal
|
|
from app.models.product import Product
|
|
from app.models.category import Category
|
|
|
|
def seed_products():
|
|
db = SessionLocal()
|
|
|
|
try:
|
|
# Get categories
|
|
category_shoes = db.query(Category).filter(Category.slug == "shoes").first()
|
|
category_shirts = db.query(Category).filter(Category.slug == "shirts").first()
|
|
category_pants = db.query(Category).filter(Category.slug == "pants").first()
|
|
|
|
if not category_shoes:
|
|
print("ERROR: Categories not found. Run schema.sql first!")
|
|
return
|
|
|
|
# Clear existing products
|
|
db.query(Product).delete()
|
|
db.commit()
|
|
print("✓ Cleared existing products")
|
|
|
|
# Products data
|
|
products = [
|
|
# Shoes
|
|
Product(
|
|
name="Premium Running Shoes",
|
|
description="High-performance running shoes with advanced cushioning technology",
|
|
price=129.99,
|
|
discount_price=99.99,
|
|
category_id=category_shoes.id,
|
|
gender="men",
|
|
brand="Nike",
|
|
sizes=["7", "8", "9", "10", "11", "12", "13"],
|
|
colors=["Black", "White", "Blue"],
|
|
stock=50,
|
|
images=["https://via.placeholder.com/300x300?text=Nike+Running"],
|
|
is_featured=True,
|
|
is_on_sale=True
|
|
),
|
|
Product(
|
|
name="Women Athletic Sneakers",
|
|
description="Comfortable athletic sneakers for everyday wear",
|
|
price=99.99,
|
|
discount_price=None,
|
|
category_id=category_shoes.id,
|
|
gender="women",
|
|
brand="Adidas",
|
|
sizes=["5", "6", "7", "8", "9", "10"],
|
|
colors=["Pink", "White", "Purple"],
|
|
stock=45,
|
|
images=["https://via.placeholder.com/300x300?text=Adidas+Sneakers"],
|
|
is_featured=True,
|
|
is_on_sale=False
|
|
),
|
|
Product(
|
|
name="Basketball High Tops",
|
|
description="Professional basketball shoes with ankle support",
|
|
price=149.99,
|
|
discount_price=None,
|
|
category_id=category_shoes.id,
|
|
gender="men",
|
|
brand="Jordan",
|
|
sizes=["8", "9", "10", "11", "12", "13"],
|
|
colors=["Red", "Black", "Gold"],
|
|
stock=30,
|
|
images=["https://via.placeholder.com/300x300?text=Jordan+High"],
|
|
is_featured=True,
|
|
is_on_sale=False
|
|
),
|
|
Product(
|
|
name="Casual Leather Loafers",
|
|
description="Classic leather loafers for formal occasions",
|
|
price=139.99,
|
|
discount_price=109.99,
|
|
category_id=category_shoes.id,
|
|
gender="men",
|
|
brand="Cole Haan",
|
|
sizes=["7", "8", "9", "10", "11", "12"],
|
|
colors=["Brown", "Black"],
|
|
stock=25,
|
|
images=["https://via.placeholder.com/300x300?text=Cole+Haan+Loafers"],
|
|
is_featured=True,
|
|
is_on_sale=True
|
|
),
|
|
Product(
|
|
name="Hiking Boot Pro",
|
|
description="Durable hiking boots with waterproof technology",
|
|
price=179.99,
|
|
discount_price=149.99,
|
|
category_id=category_shoes.id,
|
|
gender="men",
|
|
brand="Salomon",
|
|
sizes=["8", "9", "10", "11", "12", "13"],
|
|
colors=["Brown", "Gray", "Black"],
|
|
stock=35,
|
|
images=["https://via.placeholder.com/300x300?text=Salomon+Hiking"],
|
|
is_featured=True,
|
|
is_on_sale=True
|
|
),
|
|
# Clothing
|
|
Product(
|
|
name="Classic Cotton T-Shirt",
|
|
description="Comfortable everyday cotton t-shirt",
|
|
price=29.99,
|
|
discount_price=None,
|
|
category_id=category_shirts.id,
|
|
gender="men",
|
|
brand="Gap",
|
|
sizes=["S", "M", "L", "XL", "XXL"],
|
|
colors=["Red", "Blue", "White", "Black"],
|
|
stock=100,
|
|
images=["https://via.placeholder.com/300x300?text=Cotton+Tee"],
|
|
is_featured=False,
|
|
is_on_sale=False
|
|
),
|
|
Product(
|
|
name="Silk Blouse",
|
|
description="Elegant silk blouse for professional settings",
|
|
price=89.99,
|
|
discount_price=69.99,
|
|
category_id=category_shirts.id,
|
|
gender="women",
|
|
brand="Hugo Boss",
|
|
sizes=["XS", "S", "M", "L", "XL"],
|
|
colors=["White", "Black", "Navy"],
|
|
stock=40,
|
|
images=["https://via.placeholder.com/300x300?text=Silk+Blouse"],
|
|
is_featured=False,
|
|
is_on_sale=True
|
|
),
|
|
Product(
|
|
name="Slim Fit Jeans",
|
|
description="Modern slim fit jeans with stretch fabric",
|
|
price=79.99,
|
|
discount_price=59.99,
|
|
category_id=category_pants.id,
|
|
gender="men",
|
|
brand="Levi's",
|
|
sizes=["28", "30", "32", "34", "36", "38"],
|
|
colors=["Dark Blue", "Light Blue", "Black"],
|
|
stock=60,
|
|
images=["https://via.placeholder.com/300x300?text=Slim+Jeans"],
|
|
is_featured=False,
|
|
is_on_sale=True
|
|
),
|
|
Product(
|
|
name="Yoga Leggings",
|
|
description="High-waist yoga leggings with moisture-wicking",
|
|
price=89.99,
|
|
discount_price=None,
|
|
category_id=category_pants.id,
|
|
gender="women",
|
|
brand="Lululemon",
|
|
sizes=["XS", "S", "M", "L", "XL"],
|
|
colors=["Black", "Navy", "Purple", "Gray"],
|
|
stock=55,
|
|
images=["https://via.placeholder.com/300x300?text=Yoga+Leggings"],
|
|
is_featured=True,
|
|
is_on_sale=False
|
|
),
|
|
]
|
|
|
|
# Add products
|
|
for product in products:
|
|
db.add(product)
|
|
|
|
db.commit()
|
|
print(f"✓ Added {len(products)} products")
|
|
print("\n✅ Database seeded successfully!")
|
|
|
|
except Exception as e:
|
|
db.rollback()
|
|
print(f"❌ Error: {e}")
|
|
finally:
|
|
db.close()
|
|
|
|
if __name__ == "__main__":
|
|
seed_products()
|