Files
fizzy/script/migrations/rename-tenants-to-qb-account-id.rb
T
Mike Dalessio db6b700da8 Clean up the /scripts directory
Not removing anything, just organizing scripts into subdirectories to
make it a bit more readable.
2025-07-21 09:07:15 -04:00

34 lines
840 B
Ruby
Executable File

#!/usr/bin/env ruby
require_relative "../config/environment"
tenant_names = []
ApplicationRecord.with_each_tenant do |tenant|
next if tenant == "#{Rails.env}-tenant"
account = Account.sole
queenbee_id = account.queenbee_id
tenant_names << { from: tenant, to: queenbee_id }
ApplicationRecord.remove_connection
end
pp [ "Tenant name changes:", tenant_names ]
root_config = ApplicationRecord.tenanted_root_config
tenant_names.each do |name|
from_db_path = root_config.database_path_for(name[:from])
to_db_path = root_config.database_path_for(name[:to])
from_path = from_db_path.split("/").take(4).join("/")
to_path = to_db_path.split("/").take(4).join("/")
unless from_path == to_path
FileUtils.move from_path, to_path, verbose: true
end
end
puts
pp [ "Tenants after renaming:", ApplicationRecord.tenants ]