Skip to content

Commit

Permalink
Improve info logs as per suggestions
Browse files Browse the repository at this point in the history
Co-authored-by: Joan Lledó <[email protected]>
  • Loading branch information
mayorova and jlledom committed Sep 16, 2024
1 parent ee9e0a8 commit e2c5276
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/tasks/multitenant/tenants.rake
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ namespace :multitenant do

desc 'Check and remove orphaned objects (whose tenant is missing), pass "destroy" argument to delete'
task :cleanup_orphans, [:mode] => :environment do |_task, args|
puts 'Checking and removing orphaned objects...'

destroy = args[:mode] == "destroy"

puts "Checking orphaned objects..."
puts "WARNING: the found orphan objects will be destroyed" if destroy

provider_account_ids = Account.where(provider: true).pluck(:id) + [Account.master.id]
Expand All @@ -84,15 +83,15 @@ namespace :multitenant do
orphaned_objects = model.where.not(tenant_id: provider_account_ids)

if orphaned_objects.exists?
puts "Found orphaned objects in #{model.table_name}:"
puts "Found orphaned objects for model #{model.name}:"
orphaned_objects.find_each { |obj| puts "- ID: #{obj.id}, Tenant ID: #{obj.tenant_id}" }

if destroy
puts "Destroying orphan #{model.table_name}..."
puts "Destroying orphaned objects for model #{model.name}..."
orphaned_objects.in_batches(of: 100).destroy_all
end
else
puts "No orphaned objects found in #{model.table_name}."
puts "No orphaned objects found for model #{model.name}."
end
end

Expand Down

0 comments on commit e2c5276

Please sign in to comment.