Skip to content

Instantly share code, notes, and snippets.

@pythonandchips
Last active February 10, 2021 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pythonandchips/ad6f4d513cc90ebecffa304b055cdb7e to your computer and use it in GitHub Desktop.
Save pythonandchips/ad6f4d513cc90ebecffa304b055cdb7e to your computer and use it in GitHub Desktop.
Backfill recurring_invoice_profile_id
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
Copy link

djmb commented Feb 9, 2021

Are the recurring_invoice_id and recurring_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

@pythonandchips
Copy link
Author

@djmb yeah they are being kept in sync with a wee before save hook just now.

@pythonandchips
Copy link
Author

Cheers for looking at this.

@djmb
Copy link

djmb commented Feb 9, 2021

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?

@pythonandchips
Copy link
Author

@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