From e2c52764db7e135c8ab319b1b9c30fe02a8ce2a5 Mon Sep 17 00:00:00 2001 From: Daria Mayorova Date: Mon, 16 Sep 2024 11:25:56 +0200 Subject: [PATCH] Improve info logs as per suggestions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Joan Lledó --- lib/tasks/multitenant/tenants.rake | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/tasks/multitenant/tenants.rake b/lib/tasks/multitenant/tenants.rake index 205d7c1680..47ffec7f80 100644 --- a/lib/tasks/multitenant/tenants.rake +++ b/lib/tasks/multitenant/tenants.rake @@ -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] @@ -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