demo seed change 5

This commit is contained in:
Urtzi Alfaro
2025-12-14 20:13:59 +01:00
parent 82f9622411
commit 56a1821256
4 changed files with 462 additions and 173 deletions

View File

@@ -246,47 +246,60 @@ async def clone_demo_data(
# Flush to get equipment IDs
await db.flush()
# Clone Quality Check Templates
# Note: Quality check templates are not included in seed data
# They would need to be added to the production seed data if needed
# Clone Quality Check Templates from seed data
template_id_map = {}
base_templates = []
logger.info(
"No quality check templates to clone (not in seed data)",
count=len(base_templates)
)
for template_data in seed_data.get('quality_check_templates', []):
# Transform template ID using XOR
from shared.utils.demo_id_transformer import transform_id
try:
template_uuid = UUID(template_data['id'])
transformed_id = transform_id(template_data['id'], virtual_uuid)
except ValueError as e:
logger.error("Failed to parse template UUID",
template_id=template_data['id'],
error=str(e))
continue
# Only create templates if they exist in base templates
for template in base_templates:
new_template_id = uuid.uuid4()
template_id_map[template.id] = new_template_id
template_id_map[UUID(template_data['id'])] = transformed_id
# Parse date fields (supports BASE_TS markers and ISO timestamps)
adjusted_created_at = parse_date_field(
template_data.get('created_at'),
session_time,
"created_at"
) or session_time
adjusted_updated_at = parse_date_field(
template_data.get('updated_at'),
session_time,
"updated_at"
) or adjusted_created_at
new_template = QualityCheckTemplate(
id=new_template_id,
id=str(transformed_id),
tenant_id=virtual_uuid,
name=template.name,
template_code=template.template_code,
check_type=template.check_type,
category=template.category,
description=template.description,
instructions=template.instructions,
parameters=template.parameters,
thresholds=template.thresholds,
scoring_criteria=template.scoring_criteria,
is_active=template.is_active,
is_required=template.is_required,
is_critical=template.is_critical,
weight=template.weight,
min_value=template.min_value,
max_value=template.max_value,
target_value=template.target_value,
unit=template.unit,
tolerance_percentage=template.tolerance_percentage,
applicable_stages=template.applicable_stages,
created_by=template.created_by,
created_at=session_time,
updated_at=session_time
name=template_data.get('name'),
template_code=template_data.get('template_code'),
check_type=template_data.get('check_type'),
category=template_data.get('category'),
description=template_data.get('description'),
instructions=template_data.get('instructions'),
parameters=template_data.get('parameters'),
thresholds=template_data.get('thresholds'),
scoring_criteria=template_data.get('scoring_criteria'),
is_active=template_data.get('is_active', True),
is_required=template_data.get('is_required', False),
is_critical=template_data.get('is_critical', False),
weight=template_data.get('weight', 1.0),
min_value=template_data.get('min_value'),
max_value=template_data.get('max_value'),
target_value=template_data.get('target_value'),
unit=template_data.get('unit'),
tolerance_percentage=template_data.get('tolerance_percentage'),
applicable_stages=template_data.get('applicable_stages'),
created_by=template_data.get('created_by'),
created_at=adjusted_created_at,
updated_at=adjusted_updated_at
)
db.add(new_template)
stats["quality_check_templates"] += 1