from .db_core import create_categories, create_users, create_products from .db_content import create_posts, create_reviews, create_orders, create_artists def run_seed(command, options): counts = [options[key] for key in ('users', 'categories', 'products', 'posts', 'reviews', 'orders', 'artists')] if any(value < 0 for value in counts): raise ValueError('Seed counts cannot be negative.') if options['users'] == 0 and any(options[key] for key in ('products', 'posts', 'reviews', 'orders', 'artists')): raise ValueError('At least one user is required for related seed data.') if options['categories'] == 0 and options['products']: raise ValueError('At least one category is required for products.') categories = create_categories(command, options['categories']) users = create_users(command, options['users']) posts = create_posts(command, users, options['posts']) if users else [] products = create_products(command, users, categories, options['products']) if users else [] reviews = create_reviews(command, users, products, options['reviews']) if users else [] orders = create_orders(command, users, options['orders']) if users else [] artists = create_artists(command, users, options['artists']) if users else [] totals = (('Users', users), ('Categories', categories), ('Blog Posts', posts), ('Products', products), ('Reviews', reviews), ('Orders', orders), ('Artists', artists)) command.stdout.write(command.style.SUCCESS('Database seeding completed successfully!')) for label, items in totals: command.stdout.write(f'{label}: {len(items)}')