Script to correct faulty statistics table entries.
This is the first iteration of this script, likely to be expanded
if other mappings are determined. Currently it populates the
itemtype for all statistics that have itemnumbers and then pulls
borrownumbers from old_issues (or issues). This has the benign
side effect of ignoring whether or not itemtype was a different
value at the time of the transaction.
It then tries to populate null borrowernumbers using a fairly
conservative approach, only where exactly one match exists, else warns.
The process of updating statistics is needlessly complex based on the
lack of a reliable primary key. ALL such tables should have a numerical
primary key. The impression that the timestamp and any other fields
are enough to combine for a "unique enough" key is wrong. For example,
running SIP tests will add multiple transactions that might share
borrowernumber, itemnumber and timestamp. Key uniqueness should be
logically inherent, not de facto.