My Django app has a User model, those Users have many Transactions. Some of my views display a summary (summation) of all transaction amounts, let's call it the 'total'. So far, this has been tallied up when needed for display.
Now, I'd like to add this tally to essentially every page a User views... so I'd prefer it to come from a DB/model field, that's maintained with each new Transaction. I know how to do that: add a 'total' field to my User model, update it as needed (using the Django ORM F()-expressions for race-proof-ness). So far so good.
My question regards setting the initial 'total' value, tracking all Transactions so far (before the running-tally was implemented).
I suppose I could, during a maintenance window where no new Transactions arrive, do a data-migration initializing all User.total values to the current tally. However, I'd rather not do that: the last similar big data-migration I did took hours longer than expected.
Is there a recommended technique/trick for doing the catchup tallying without a long outage, while new transactions are also arriving?
I suppose I could write the catchup data-migration to consider only transactions before the threshold date (or id) at the moment the new, tally-maintaining code is deployed. (Then, I'd run the data-migration while the system is up, and only reveal the new tallies in the interface when the migration completes, no matter how long that takes.) However, I'd rather not code this date/id threshold into the migration source code. Is there South metadata that could be used for this purpose?