Credit-card billing cycles: domain logic and a migration that freezes history
The day you swipe a card is not the month you're accounting for. Here's how I modelled credit-card billing cycles as a pure function, applied it in one save hook, and used an irreversible migration to stop a future rule change from rewriting the past.