Currently when I run crowdmatch 2020 08 01, it'll record a crowdmatch on that date in the database. But it won't record that the match was run today, 2021年07月01日. We should store both. Also, they should both include a timestamp, although it's currently always midnight UTC.
Implementation notes (outdated)
We could do this in a simpler way, but this kicks off updating the DB to support our long-term, multiple-projects-and-goals plan (see snowdrift/snowdrift!253 for a draft of what the end state might look like).
- Update the DB
- Rename
CrowdmatchHistorytable toDonation - Rename
DonationHistorytoPaymentHistory(for sanity) - Add
CrowdmatchandFinalCrowdmatchtables - Populate
Crowdmatchtable based on data inDonationtable (group by date and count pledges, then math progress) - Populate
FinalizedCrowdmatchtable manually-ish.- Most crowdmatches were run on the 3rd of the month. Then there was one day where we started actually running crowdmatches, which processed a few years' worth. (TODO: find that date).
- All final goal progress will be equal to initial goal progress since we are not dropping yet.1
- Update
Donationtable.- Add
Crowdmatchcolumn, by joining onCrowdmatchtable by date. - Add
PledgeAmountcolumn, default 600 cents (technically it was 10ドル very early on when we had a "limit" framing, but we never exceeded that so it won't make a material difference). - VERIFY locally that for all rows,
Donation.amount == (FinalCrowdmatch.amount / Crowdmatch.goalAmount) * Donation.pledgeAmount. Once confirmed, dropDonation.pledgeAmount.
- Add
- Add
DonationOutcometable. One row for eachDonationrow. Allstatus=Confirmed.1
- Rename
- Add
startCrowdmatchaction (to run on the first of each month). Takes a start date and finalize date.- Add a new row the the
Crowdmatchtable - For each patron who is pledged, add a
Donation
- Add a new row the the
- Add
finishCrowdmatchaction (to run on the 4th of each month). Takes just a start date.
For theCrowdmatchwith the given start date, only if it doesn't have a correspondingFinalizedCrowdmatchyet:- For each linked
Donationwith no correspondingDonationOutcome, check the pledge history to see if the pledge was still active on the current date. Create aDonationStatusfor that donation with eitherstatus=Confirmedorstatus=DroppedPledge. - Create a
FinalizedCrowdmatchwith the curent date and thefinalGoalProgress= sum(donations for this crowdmatch with status=Confirmed)
- For each linked
1Technically this is wrong since a few patrons were dropped. we could sleuth through the history and see which patrons were dropped, add a Donation for them and corresponding DonationOutcome with status=Unpledged, and then calculate the correct initialProgress on the Crowdmatch from that. But it's not worth the effort; the final pledge amount is correct and in this pre-alpha stage that's what matters.