Skip to content

Instantly share code, notes, and snippets.

@pythonandchips
Last active February 10, 2021 09:23
Show Gist options
  • 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
@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