fix: BUG-01 ETL (type crash + cartesian explosion), BUG-02 multi-account audit, BUG-03 diagnostic #12
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/bugs-01-02-03"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
First tranche of fixes from the recent code audit. CRITICAL + HIGH severity items only.
dwh_gold.refresh_daily_metrics()insertedt.imei(TEXT) intofact_daily_fleet_metrics.vehicle_key(INTEGER REFERENCES dim_vehicles), so the nightly ETL would have raisedinvalid input syntax for type integeron every run.trips × alarmsin a single SELECT, producing one row per (trip, alarm) pair. Every SUM/COUNT over trip columns was multiplied by the per-IMEI alarm count. Spot-checks on a corrected ad-hoc version of the SELECT showed total_trips identical to alarm_count, drive_hours > 1000/day, and total_distance_km in the tens of thousands per vehicle per day. Without this second fix, the ETL would have stopped crashing but produced garbage metrics.Migration
08_fix_etl_vehicle_key.sqlresolves both:dwh_gold.dim_vehiclesfromtracksolid.devicesso every IMEI has a serialvehicle_key.refresh_daily_metrics()to computetrip_aggandalarm_aggin separate CTEs, then joins the aggregates on IMEI and maps IMEI → vehicle_key viadim_vehicles.dim_vehiclesat the top of each call so newly registered devices appear in the warehouse without manual seeding.sync_driver_audit.pyonly queriedTARGET_ACCOUNT, ignoring theFireside@HQandFireside_MSAsub-accounts. The audit now iteratesTARGETS(matching FIX-M19 iningest_movement_rev.sync_devices), dedupes devices by IMEI, and tolerates per-target failures.item["miles"]straight intodistance_km. The field name is suspicious and FIX-M16 already proved the polling endpoint mis-documents its units. Addeddb_audit/checks/bug03_webhook_distance_units.sqlwhich compares the distribution ofstored_km / great_circle_kmfor push-source vs poll-source trips over 30 days — the ratio test will tell us whether the push value needs/1.609(miles),/1000(metres), or no conversion. The existing calculation is left unchanged until the data confirms; the misleading[FIX-M11]comment is replaced with a[BUG-03]pointer to the diagnostic.Test plan
08_fix_etl_vehicle_key.sqlon container restart.dwh_gold.dim_vehiclesrow count equalstracksolid.devicesrow count.SELECT dwh_gold.refresh_daily_metrics(CURRENT_DATE - 1);— should succeed (previously crashed).dwh_gold.fact_daily_fleet_metricsrows for yesterday show plausible values:total_tripsin single/double digits,total_drive_hours ≤ 24,alarm_countdecoupled fromtotal_trips.python sync_driver_audit.pyinside theingest_movementcontainer — total device count should match the union of all sub-accounts, not just one.db_audit/checks/bug03_webhook_distance_units.sqland capture the per-source median ratio; if push median ≈ 1.609× poll median, raise a follow-up to divide the webhookmilesvalue.Notes
🤖 Generated with Claude Code
fix: BUG-01 ETL type crash, BUG-02 multi-account audit, BUG-03 diagnosticto fix: BUG-01 ETL (type crash + cartesian explosion), BUG-02 multi-account audit, BUG-03 diagnosticView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.