Code cleanups
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
class Migration::SetDefaultValueForContactNameJob < ApplicationJob
|
||||
queue_as :scheduled_jobs
|
||||
|
||||
def perform(account)
|
||||
account.contacts.each do |contact|
|
||||
# Set default value for contact name if it is blank
|
||||
# rubocop:disable Rails/SkipsModelValidations
|
||||
contact.update_columns(name: '') if contact.name.blank?
|
||||
# rubocop:enable Rails/SkipsModelValidations
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,13 +1,10 @@
|
||||
class SetDefaultNameToExistingContacts < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
Contact.where(name: nil).each do |contact|
|
||||
contact.update(name: '')
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
Contact.where(name: '').each do |contact|
|
||||
contact.update(name: nil)
|
||||
::Account.find_in_batches do |account_batch|
|
||||
Rails.logger.info "Migrated till #{account_batch.first.id}\n"
|
||||
account_batch.each do |account|
|
||||
Migration::SetDefaultValueForContactNameJob.perform_later(account)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user