Files
factoryOps-v2/alembic/versions/f8a9b0c1d2e3_backfill_machine_area_criticality.py
Johngreen 62e54ae2ef
All checks were successful
Deploy to Production / deploy (push) Successful in 48s
feat: replace spifox seed data with real factory data from business plan
- Replace semiconductor equipment with actual press forming equipment (14 machines)
- Add real equipment: cup presses, finish presses, dryer, washer, heat treatment,
  vision inspectors, conveyor, AMR across 6 area groups
- Add real die parts: cut pin, cut die, forming die with count-based lifecycles
- Add press daily inspection + heat treatment inspection + case dimension inspection templates
- Fix seed.py to pass area/criticality when creating machines
- Add backfill migration to populate area/criticality for existing DB records
- Change spifox industry_type from semiconductor to press_forming
2026-02-10 22:45:53 +09:00

51 lines
1.2 KiB
Python

"""backfill machine area and criticality from existing location data
Revision ID: f8a9b0c1d2e3
Revises: e7f8a9b0c1d2
Create Date: 2026-02-10 19:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
revision: str = "f8a9b0c1d2e3"
down_revision: Union[str, None] = "e7f8a9b0c1d2"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def _extract_area(location: str) -> str:
parts = location.strip().split(" ", 1)
if len(parts) > 1:
return parts[1]
return location
def upgrade() -> None:
conn = op.get_bind()
rows = conn.execute(
sa.text(
"SELECT id, location FROM machines WHERE area IS NULL AND location IS NOT NULL"
)
).fetchall()
for row in rows:
machine_id, location = row[0], row[1]
area = _extract_area(location)
conn.execute(
sa.text("UPDATE machines SET area = :area WHERE id = :id"),
{"area": area, "id": machine_id},
)
conn.execute(
sa.text("UPDATE machines SET criticality = 'major' WHERE criticality IS NULL")
)
def downgrade() -> None:
pass