MOVILBA-125 code: current-SSOT wide-history writer and reconciliation
Done high
cmcoder-mba-l-ca
Implement the application-owned writer that reads the sole current rutap.v_rutap_latest snapshot and rebuilds/upserts the additive wide history table field-for-field. Resolve option IDs through canonical views, preserve literal 0, record conflicts on the same row, import every Base row, and produce idempotency plus source-to-history reconciliation. Do not write legacy vehiculo_historial or VDC.
Sub-tickets — 1/1 done
Activity
-
parent=#3027
-
Implementing the current-SSOT wide-history writer contract while DB03 supplies the additive DEV schema.
-
Added typed repository/service/server-action boundary for additive RUTAP vehicle history. Contract review found and escalated a source-fidelity hole in the proposed DB schema before DDL; reader wiring will target the corrected field-for-field contract.
-
DB03's first DEV DDL populated data itself and used lossy/hardcoded mappings. Writer contract remains open: move repeatable population/reconciliation into repository-owned tooling, preserve all raw fields alongside resolved IDs, and use canonical views including GNC -> GN mapping.
-
Catalogs are authoritative and read-only during RUTAP import. Source-to-catalog equivalences must come from the existing explicit mapping table/view, never an inline alias or catalog mutation. Every accepted mapping needs provenance/documentation; unmatched values remain row-level conflicts and enter Eugenia's Spanish tracker for a canonical mapping decision or source correction.
-
db03: DEV wide table refreshed to snapshot 10 (5370 rows, snapshot 9 replaced, 0 unresolved vehiculo_id, view 2406/0 multiple-open). File docs/migrations/2026-09-04-movilba-203-wide-refresh-snapshot10-DEV.sql uncommitted in shared checkout.
-
Elazar 2026-09-04: no more deferring - see MOVILBA-125 decision of this date. Writer must target the wide table and must handle a second snapshot: current writer is INSERT ON CONFLICT (snapshot_id, fila_excel) DO NOTHING with no delete of the prior snapshot, and v_vehiculo_historial_actual has no snapshot filter.
-
Replace-on-snapshot writer implemented; DEV rerun gate delegated to db03 and code audit to audit.
-
Wide history is a one-workbook mirror: in one transaction remove stale snapshots, remove the selected snapshot's prior materialisation, then insert every current raw row. This forces vehiculo and catalog resolution on every run. The five VDC-only fields remain NULL and are asserted after load.
-
Conflict scope is row-level: only duplicate open events receive multiples_eventos_abiertos; closed history is retained and eligible. Chassis IDs come only from rutap.v_rutap_chasis_resuelto_aprobado. No approved carroceria resolver exists, so carroceria_id remains NULL with source text and carroceria_no_resuelta.
-
Synthetic rollback fixture will be versioned next to the writer. Its pg_temp schema-rewrite ceiling must be stated: branch logic is verified, not literal execution against the schema-qualified production table.
-
Correction: absence of any approved carroceria resolver is a catalog-capability gap, not a per-row failed resolution. The writer retains raw carroceria text and carroceria_id NULL without adding carroceria_no_resuelta. Chassis has an approved resolver with 50 rows covered; remaining nonblank chassis values are row-level chasis_no_resuelto pending reviewed mapping.
-
normalizacion_estado now distinguishes resuelto, pendiente, and conflicto. Pending means a source row is retained but awaits approved catalog mapping (currently chassis); it remains eligible. Conflict means an attempted resolution/data validation failed. This prevents our approval backlog from being reported as an SSOT defect.
-
Final pending-vs-conflict semantics implemented; db03 is running the current checksum twice in DEV and audit is reviewing it.
-
DEV double run accepted: immutable a0558f98 / SHA dcc97e31 was re-hashed before both committed runs; 5,370/5,370 snapshot-10 rows, zero duplicate vehicle/source pairs, VDC-only fields NULL, and identical content signature across rerun. 5,048 eligible; pending catalog approval is retained as eligible, while 322 true conflicts remain reported on-row. MOVILBA-245 owns the approved carroceria resolver.
feature
6w ago by wi-cli-venus
5w ago
2026-09-05 01:53