Files
shopdb-flask/scripts/site_imports/wjf
cproudlock 6d79e469fa
Some checks failed
CI / backend (push) Successful in 1m38s
CI / naming (push) Successful in 1s
CI / frontend (push) Successful in 8s
CI / migrations-mysql (push) Failing after 8s
WJ import loader: dependent-entity stages (comms, apps/installs, warranty, notif, KB)
All consume the machineid->assetid crosswalk from the assets hub. Verified
against the scratch target, zero endpoint errors:

- communications: 435 primary IPs folded onto assets. No bulk endpoint exists,
  so this is the plan's documented direct-ORM gap (reads the source
  communications table where comstypeid=1 AND isprimary=1, not machines.ipaddress1
  which is empty).
- applications: supportteams 45, applications 121 (colliding names dedup via the
  unique-appname 409-resolve), appversions 47, installs 653 (machineid ->
  assetid -> computerid; only computer assets take installs).
- warranties: 424 linked, vendor hardcoded Dell (source has none).
- notifications: types 6, notifications 261 (2099 sentinel endtime clamped).
- knowledgebase: 341 (appid resolved through the applications name map).

Inactive rows skipped everywhere per the decisions. Remaining loader stages:
locations (the 158 LocationOnly rows), relationships (301 active edges),
subnets/VLANs, usb (cmmc pairing), verify.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-13 11:43:02 -04:00
..

WJ classic-ASP import loader (reference implementation)

This is site-specific reference glue, not product code. It maps West Jefferson's classic-ASP shopdb / cmmc_usb / wjf_employees schema onto the maintained, schema-agnostic import contract in docs/IMPORT-API.md.

Every adopting site has its own source database. Nobody else runs this loader. Instead, copy the pattern:

  1. Point the harness at your source DB(s) (edit harness.Source).
  2. Write per-entity stages that read your tables and POST to the same docs/IMPORT-API.md endpoints with Authorization: Bearer <admin PAT> and X-Import-Mode: true.
  3. Persist legacy-id -> new-id crosswalks (see harness.IdMap) so later stages resolve foreign keys and a crashed run resumes.

The import API is the stable contract; loaders are per-site. The mapping itself can be produced with the agent-assisted workflow (point Fable/Opus agents at a source DB + this contract -> they emit the mapping + a loader skeleton).

Running (against a THROWAWAY import database)

DATABASE_URL='mysql+pymysql://root:PW@127.0.0.1:3306/shopdb_flask_import?charset=utf8mb4' \
  venv/bin/python -m scripts.site_imports.wjf.run --stages reference,employees

Prereqs: a fresh target DB built with flask db upgrade + flask plugin upgrade-all + flask seed permissions/settings/reference-data, and the three source dumps loaded into scratch DBs (shopdb_src, cmmc_usb_src, wjf_employees_src). See scratchpad/IMPORT-PLAN.md for the full mapping, resolved decisions, and remaining stages.

Status

  • Implemented + verified idempotent: reference (vendors, businessunits, operatingsystems), employees (directory bulk upsert; photos deferred).
  • TODO stages: models, applications, assets (the hub - fan machines out by type, persist the machineid->assetid crosswalk), dependents (installs, warranties, notifications, KB), network (+ subnets/VLANs), usb (cmmc device + checkinout pairing), verify.

The harness (PAT auth, import-mode, id-map persistence, endpoint error capture) is proven; the remaining stages are additional stage_* functions in run.py following the same shape.