Last active
February 10, 2021 09:23
-
-
Save pythonandchips/ad6f4d513cc90ebecffa304b055cdb7e to your computer and use it in GitHub Desktop.
Backfill recurring_invoice_profile_id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def backfill_recurring_invoice_profile_id | |
ids = RecurringInvoiceProfile.select(:id) | |
progress_bar = ProgressBar.new(ids.count) | |
RecurringInvoiceProfile.select(:id).find_each do |recurring_invoice_profile| | |
Invoice.where(recurring_invoice_id: recurring_invoice_profile.id). | |
update_all(recurring_invoice_profile_id: recurring_invoice_profile.id) | |
progress_bar.increment! | |
end | |
end |
@djmb yeah they are being kept in sync with a wee before save hook just now.
Cheers for looking at this.
Ah cool - does that mean the table isn’t in sync with the auto increment key? If so is there a plan to avoid ID clashes in future?
@djmb the auto increment keys are currently in sync between RecurringInvoice#id (old model) and RecurringInvoiceProfile#id (new model) so we shouldn't have an issue with ID clashes in the future.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Are the
recurring_invoice_id
andrecurring_invoice_profile_id
being kept in sync with each other? If so this script looks good.The only thing I'd add is that I don't think we need to rate limit the scripts any more now we are on Aurora, or at least you could probably have the script run a lot faster. Might be worth doublechecking with ops