Compare commits

...
Author SHA1 Message Date
Muhsin Keloth 82270e9405 Update schema.rb 2023-05-12 10:00:07 +05:30
Muhsin Keloth 18d9271891 Remove the comment 2023-05-12 09:56:49 +05:30
Muhsin Keloth f65e479fe7 Code cleanups 2023-05-12 09:55:55 +05:30
Muhsin Keloth 7607752fdf Add migration to set default values for contacts 2023-05-12 09:43:54 +05:30
3 changed files with 22 additions and 1 deletions
@@ -0,0 +1,11 @@
class Migration::SetDefaultValueForContactNameJob < ApplicationJob
queue_as :scheduled_jobs
def perform(account)
account.contacts.each do |contact|
# rubocop:disable Rails/SkipsModelValidations
contact.update_columns(name: '') if contact.name.blank?
# rubocop:enable Rails/SkipsModelValidations
end
end
end
@@ -0,0 +1,10 @@
class SetDefaultNameToExistingContacts < ActiveRecord::Migration[7.0]
def change
::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
+1 -1
View File
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_05_10_113208) do
ActiveRecord::Schema[7.0].define(version: 2023_05_12_040636) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
enable_extension "pg_trgm"