Improve demo seed

This commit is contained in:
Urtzi Alfaro
2025-10-17 07:31:14 +02:00
parent b6cb800758
commit d4060962e4
56 changed files with 8235 additions and 339 deletions

View File

@@ -8,6 +8,7 @@ from typing import Dict, Any, List
import httpx
import structlog
import uuid
import os
from app.core.redis_wrapper import DemoRedisWrapper
from app.core import settings
@@ -64,7 +65,8 @@ class DemoDataCloner:
service_name,
base_demo_tenant_id,
virtual_tenant_id,
session_id
session_id,
demo_account_type
)
stats["services_cloned"].append(service_name)
stats["total_records"] += service_stats.get("records_cloned", 0)
@@ -110,7 +112,8 @@ class DemoDataCloner:
service_name: str,
base_tenant_id: str,
virtual_tenant_id: str,
session_id: str
session_id: str,
demo_account_type: str
) -> Dict[str, Any]:
"""
Clone data for a specific service
@@ -120,21 +123,26 @@ class DemoDataCloner:
base_tenant_id: Source tenant ID
virtual_tenant_id: Target tenant ID
session_id: Session ID
demo_account_type: Type of demo account
Returns:
Cloning statistics
"""
service_url = self._get_service_url(service_name)
# Get internal API key from environment
internal_api_key = os.getenv("INTERNAL_API_KEY", "dev-internal-key-change-in-production")
async with httpx.AsyncClient(timeout=30.0) as client:
response = await client.post(
f"{service_url}/internal/demo/clone",
json={
"base_tenant_id": base_tenant_id,
"virtual_tenant_id": virtual_tenant_id,
"session_id": session_id
"session_id": session_id,
"demo_account_type": demo_account_type
},
headers={"X-Internal-Service": "demo-session"}
headers={"X-Internal-Api-Key": internal_api_key}
)
response.raise_for_status()
@@ -261,7 +269,17 @@ class DemoDataCloner:
)
# Delete from each service
services = ["inventory", "recipes", "sales", "orders", "production", "suppliers", "pos"]
# Note: Services are deleted in reverse dependency order to avoid foreign key issues
services = [
"forecasting", # No dependencies
"sales", # Depends on inventory, recipes
"orders", # Depends on customers (within same service)
"production", # Depends on recipes, equipment
"inventory", # Core data (ingredients, products)
"recipes", # Core data
"suppliers", # Core data
"pos" # Point of sale data
]
for service_name in services:
try:
@@ -282,8 +300,11 @@ class DemoDataCloner:
"""Delete data from a specific service"""
service_url = self._get_service_url(service_name)
# Get internal API key from environment
internal_api_key = os.getenv("INTERNAL_API_KEY", "dev-internal-key-change-in-production")
async with httpx.AsyncClient(timeout=30.0) as client:
await client.delete(
f"{service_url}/internal/demo/tenant/{virtual_tenant_id}",
headers={"X-Internal-Service": "demo-session"}
headers={"X-Internal-Api-Key": internal_api_key}
)