Files
shopdb-flask/scripts/site_imports/wjf
cproudlock 40a89b360a
Some checks failed
CI / backend (push) Successful in 1m38s
CI / naming (push) Successful in 1s
CI / frontend (push) Successful in 7s
CI / migrations-mysql (push) Failing after 8s
WJ import loader: route LocationOnly by the islocationonly bit, not machinetypeid
Of the 158 machinetypeid=1 rows, only 24 carry the islocationonly bit (real
named areas: DT Office, IT Closet, Materials, ...). The other 134 are active,
modelled shop machines just left untyped - routing all 158 to Locations dropped
those 134 real assets. Route on the bit instead; the 134 untyped rows import as
machines with a null subtype (machinetypeid=1 is not a real machine subtype, so
catalog skips seeding one).

Also process asset routes in richness order (computer > measuringtool > network
> machine) so on a duplicate machinenumber the PC - which carries installs + IP
a bare untyped machine does not - wins first-come.

Result on the scratch target: 933 assets (computer 663, machine 76, network 58,
measuringtool 136), 24 locations (was mis-routing 158), installs 850 (was 653 -
PCs no longer lose their numbers to bare machines), warranties 464, comms 461.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-13 11:55:25 -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.