docs(reports): rerun the ninety-day reconciliation from a fresh restore
Rebuilt the whole analysis from nothing: fresh restore of backup point 209608347, deactivate the ten shared locations, re-key and split every one of 19,040,785 orders, re-import from Square, then two full ninety-day recomputes — one with the fixes off, one with them on. The baseline is now a no-fix recompute rather than production's stored summaries. That is the stricter comparison: production's figures are in places months stale, and crediting the fixes with repairing ordinary staleness flattered them. On the fairer footing the two arithmetic fixes are worth 979 client-days and $61,769.56, taking the window from 1,258 days out of balance ($69,560.10) to 279 ($7,790.54), with zero days knocked out of balance and zero already-balanced days altered at line level. The migration now runs to completion database-wide: 17,047,142 payments scoped, nothing left to rename, nothing unscopable, and no payment owned by more than one order across 400,000 orders checked. The earlier "transactor-bound, two days" diagnosis was wrong — the bottleneck was GC in the driving process; the full pass takes about thirteen minutes. Also corrects compare-sales-summaries: :ledger-mapped/amount, ledger-side and account are :db/noHistory, so as-of cannot recover past amounts and a rewritten summary reads back as a false balanced day. Every figure in the report comes from live captures taken straight after each pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,14 +1,25 @@
|
||||
(ns auto-ap.jobs.compare-sales-summaries
|
||||
"Compares sales summaries between two points in the same database.
|
||||
|
||||
Datomic keeps every past value, so a recompute can be audited against exactly what was there
|
||||
before by reading `(d/as-of db t)` for some earlier `t` — no snapshot or scratch copy needed.
|
||||
|
||||
The question this exists to answer is narrower than \"did the totals improve\": it is *which
|
||||
days changed, and were any of them already balanced*. A day that was balanced before and still
|
||||
balances after can still have had its line amounts move, and that is a real change to the
|
||||
books even though no red turns green. Counting only balanced/unbalanced transitions would hide
|
||||
it entirely."
|
||||
it entirely.
|
||||
|
||||
DO NOT USE `compare-against` — OR ANY `d/as-of` DATABASE — TO COMPARE AMOUNTS. The obvious
|
||||
reading is that Datomic keeps every past value, so a recompute can be audited against what was
|
||||
there before with no snapshot. That does not hold here: `:ledger-mapped/amount`,
|
||||
`:ledger-mapped/ledger-side` and `:ledger-mapped/account` are all `:db/noHistory true`, so
|
||||
superseded values are discarded rather than retained. A summary that has since been recomputed
|
||||
reads back through `as-of` with its categories intact and its amounts *absent* — which is
|
||||
indistinguishable from a legitimate all-zero day, and quietly turns every rewritten summary
|
||||
into a false \"was balanced, still balances\".
|
||||
|
||||
To compare amounts, capture `summaries-in` from a live `(d/db conn)` immediately after each
|
||||
run, keep the two captures outside the database, and diff those. `compare-window` is safe when
|
||||
both arguments are live database values; only the historical read is unsound. Categories and
|
||||
which-days-changed do survive `as-of`, since `:sales-summary-item/category` retains history."
|
||||
(:require
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[auto-ap.datomic.sales-summaries :as d-ss]
|
||||
@@ -119,7 +130,11 @@
|
||||
(into {}))))
|
||||
|
||||
(defn compare-against
|
||||
"Convenience: compare the current database against its own past value at basis `t`."
|
||||
"Compare the current database against its own past value at basis `t`.
|
||||
|
||||
UNSOUND FOR AMOUNTS — see the namespace docstring. The amount, side and account attributes are
|
||||
`:db/noHistory`, so any summary rewritten since `t` reads back with no amounts and appears
|
||||
balanced. Kept only for comparing categories and identifying which days changed."
|
||||
[t start end]
|
||||
(let [db (dc/db conn)]
|
||||
(compare-window (dc/as-of db t) db start end)))
|
||||
|
||||
Reference in New Issue
Block a user