Refactor database seeder to improve error handling and maintainability
This commit is contained in:
parent
172f035d77
commit
717ec1e061
@ -9,19 +9,23 @@ from app.seeders.user_seeder import seed_users
|
||||
|
||||
|
||||
def seed_all(db: Session, count: int = 5):
|
||||
business_types = seed_business_types(db, count)
|
||||
plans = seed_plans(db, count)
|
||||
try:
|
||||
business_types = seed_business_types(db, count)
|
||||
plans = seed_plans(db, count)
|
||||
|
||||
bt_ids = [bt.id for bt in business_types]
|
||||
tenants = seed_tenants(db, count, business_type_ids=bt_ids)
|
||||
bt_ids = [bt.id for bt in business_types]
|
||||
tenants = seed_tenants(db, count, business_type_ids=bt_ids)
|
||||
|
||||
plan_ids = [p.id for p in plans]
|
||||
tenant_ids = [t.id for t in tenants]
|
||||
seed_subscriptions(db, count, tenant_ids=tenant_ids, plan_ids=plan_ids)
|
||||
plan_ids = [p.id for p in plans]
|
||||
tenant_ids = [t.id for t in tenants]
|
||||
seed_subscriptions(db, count, tenant_ids=tenant_ids, plan_ids=plan_ids)
|
||||
|
||||
users = seed_users(db, count)
|
||||
users = seed_users(db, count)
|
||||
|
||||
db.commit()
|
||||
db.commit()
|
||||
except:
|
||||
db.rollback()
|
||||
raise
|
||||
|
||||
return {
|
||||
"business_types": len(business_types),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user