Spaces:
Running
Running
Download backend/app/seed_data.py from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 5.81 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/app/seed_data.py
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/backend/app/seed_data.py
-
curl -L -o seed_data.py https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/app/seed_data.py
5.81 kB
| """ | |
| Seed database with demo tenant and data for DEVELOPMENT ONLY. | |
| WARNING: This file should NEVER be executed in production! | |
| It contains hardcoded demo data and UUIDs for development/testing purposes only. | |
| """ | |
| from uuid import UUID | |
| from sqlmodel import Session | |
| from app.core.database import sync_engine | |
| from app.core.config import settings | |
| from app.models.tenant import Tenant | |
| from app.models.partner import Partner | |
| from app.models.lead import Lead, Psychotype, LeadStatus, LeadHeat | |
| from datetime import datetime, timedelta | |
| # Fixed UUIDs for development (matches frontend constants) | |
| # WARNING: These should NOT exist in production databases | |
| DEMO_TENANT_ID = UUID("a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11") | |
| DEMO_PARTNER_ID = UUID("b1ffcd99-8d1c-5ef9-bc7e-7cc0ce491b22") | |
| def seed_database(): | |
| """ | |
| Seed database with demo data. | |
| CRITICAL: This function will exit immediately if ENVIRONMENT is not 'development'. | |
| This prevents accidental execution in production. | |
| """ | |
| # SAFETY CHECK: Prevent running in production | |
| if settings.ENVIRONMENT.lower() != 'development': | |
| print("\n" + "="*80) | |
| print("⛔ SECURITY WARNING: seed_data.py is for DEVELOPMENT ONLY!") | |
| print(f" Current environment: {settings.ENVIRONMENT}") | |
| print(" Seeding skipped to protect production data.") | |
| print("="*80 + "\n") | |
| return | |
| # Import here to ensure all models are loaded | |
| from app.core.database import create_db_and_tables | |
| # Create tables first | |
| create_db_and_tables() | |
| with Session(sync_engine) as session: | |
| # Check if tenant already exists | |
| existing_tenant = session.get(Tenant, DEMO_TENANT_ID) | |
| if existing_tenant: | |
| print("✅ Demo tenant already exists") | |
| return | |
| # Create Partner | |
| partner = Partner( | |
| id=DEMO_PARTNER_ID, | |
| user_id=UUID("d2aafe00-9e3e-6ab1-ee9a-9ee2ea603d44"), # Demo user ID | |
| company_name="Digital Agency Pro", | |
| contact_email="partner@digitalagency.pro", | |
| referral_code="REF-2025", # Real unique partner code | |
| commission_rate=0.5, | |
| balance_usd=2450.50, | |
| is_active=True | |
| ) | |
| session.add(partner) | |
| # Create Tenant | |
| tenant = Tenant( | |
| id=DEMO_TENANT_ID, | |
| name="MicroFunnel Demo", | |
| business_name="MicroFunnel Demo", | |
| subscription_plan="GROWTH", | |
| telegram_bot_token=None, # Users must connect their own bot via /channels page | |
| partner_id=DEMO_PARTNER_ID, | |
| is_active=True | |
| ) | |
| session.add(tenant) | |
| # Create demo leads | |
| demo_leads = [ | |
| Lead( | |
| tenant_id=DEMO_TENANT_ID, | |
| name="Алексей Петров", | |
| telegram_id="demo_user_1", | |
| status=LeadStatus.IN_PROGRESS, | |
| heat_score=85, | |
| heat_level=LeadHeat.HOT, | |
| psychotype=Psychotype.DOMINANT, | |
| budget="$5000-10000", | |
| authority="CEO", | |
| need="Автоматизация продаж", | |
| timeline="1-2 месяца", | |
| ai_summary_json={ | |
| "summary": "Целеустремленный CEO ищет быстрое решение для автоматизации продаж", | |
| "budget": "$5000-10000 готов инвестировать", | |
| "pain_points": "Тратит слишком много времени на обработку лидов вручную", | |
| "manager_recommendation": "Готов к закрытию. Предложить demo call на этой неделе" | |
| }, | |
| first_message_at=datetime.utcnow() - timedelta(hours=2), | |
| last_message_at=datetime.utcnow() - timedelta(minutes=15) | |
| ), | |
| Lead( | |
| tenant_id=DEMO_TENANT_ID, | |
| name="Мария Иванова", | |
| telegram_id="demo_user_2", | |
| status=LeadStatus.IN_PROGRESS, | |
| heat_score=65, | |
| heat_level=LeadHeat.WARM, | |
| psychotype=Psychotype.CONSCIENTIOUS, | |
| budget="Уточняется", | |
| need="Улучшение конверсии", | |
| timeline="2-3 месяца", | |
| ai_summary_json={ | |
| "summary": "Аналитический маркетолог изучает решения для улучшения воронки", | |
| "pain_points": "Низкая конверсия в текущей воронке продаж", | |
| }, | |
| first_message_at=datetime.utcnow() - timedelta(days=1), | |
| last_message_at=datetime.utcnow() - timedelta(hours=3) | |
| ), | |
| Lead( | |
| tenant_id=DEMO_TENANT_ID, | |
| name="Дмитрий Козлов", | |
| telegram_id="demo_user_3", | |
| status=LeadStatus.NEW, | |
| heat_score=45, | |
| heat_level=LeadHeat.COLD, | |
| psychotype=Psychotype.INFLUENTIAL, | |
| first_message_at=datetime.utcnow() - timedelta(hours=6), | |
| last_message_at=datetime.utcnow() - timedelta(hours=6) | |
| ), | |
| ] | |
| for lead in demo_leads: | |
| session.add(lead) | |
| session.commit() | |
| print("\n" + "="*80) | |
| print("✅ DEVELOPMENT DATABASE SEEDED SUCCESSFULLY") | |
| print(f" Demo Tenant ID: {DEMO_TENANT_ID}") | |
| print(" Note: This is DEMO DATA for development only!") | |
| print("="*80 + "\n") | |
| if __name__ == "__main__": | |
| seed_database() | |