Code cleanups

This commit is contained in:
Muhsin Keloth
2023-05-12 09:55:55 +05:30
parent 7607752fdf
commit f65e479fe7
2 changed files with 17 additions and 8 deletions
@@ -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