class MongodbLogger::Utils::Migrate
Public Class Methods
new()
click to toggle source
# File lib/mongodb_logger/utils/migrate.rb, line 8 def initialize raise "this task work only in Rails app" unless defined?(Rails) end
Public Instance Methods
create_migration_collection(configuration)
click to toggle source
# File lib/mongodb_logger/utils/migrate.rb, line 33 def create_migration_collection(configuration) configuration.merge!({ 'collection' => "#{configuration['collection']}_copy_#{rand(100)}" }) migrate_logger = MongoMigrateLogger.new(configuration) migrate_logger.mongo_adapter.reset_collection migrate_logger end
get_mongo_adapter_and_name()
click to toggle source
# File lib/mongodb_logger/utils/migrate.rb, line 27 def get_mongo_adapter_and_name mongodb_logger = Rails.logger collection_name = mongodb_logger.db_configuration['collection'].dup [mongodb_logger.mongo_adapter, collection_name] end
run()
click to toggle source
# File lib/mongodb_logger/utils/migrate.rb, line 12 def run Progressbar.new.show("Importing data to new capped collection") do @mongo_adapter, collection_name = get_mongo_adapter_and_name @migrate_logger = create_migration_collection(Rails.logger.db_configuration) iterator, all_count = 0, @mongo_adapter.collection.find.count @mongo_adapter.collection.find.each do |row| @migrate_logger.mongo_adapter.collection.insert(row) progress (((iterator += 1).to_f / all_count.to_f) * 100).round end if all_count > 0 progress 100 @migrate_logger.mongo_adapter.rename_collection(collection_name, true) end end