From 2dd925c18ca214e89e693dc87b41d78bd1f42dee Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Mon, 13 Oct 2014 15:01:14 -0500 Subject: [PATCH] Move add_rails_engine_migration_paths to Msf::DBManager::Migration MSP-11124 --- lib/msf/core/db_manager.rb | 26 -------------------------- lib/msf/core/db_manager/migration.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/msf/core/db_manager.rb b/lib/msf/core/db_manager.rb index e904671c89..b78ea82cd2 100644 --- a/lib/msf/core/db_manager.rb +++ b/lib/msf/core/db_manager.rb @@ -207,32 +207,6 @@ class DBManager true end - # Loads Metasploit Data Models and adds its migrations to migrations paths. - # - # @return [void] - def add_rails_engine_migration_paths - unless defined? ActiveRecord - fail "Bundle installed '--without #{Bundler.settings.without.join(' ')}'. To clear the without option do " \ - "`bundle install --without ''` (the --without flag with an empty string) or `rm -rf .bundle` to remove " \ - "the .bundle/config manually and then `bundle install`" - end - - Rails.application.railties.engines.each do |engine| - migrations_paths = engine.paths['db/migrate'].existent_directories - - migrations_paths.each do |migrations_path| - # Since ActiveRecord::Migrator.migrations_paths can persist between - # instances of Msf::DBManager, such as in specs, - # migrations_path may already be part of - # migrations_paths, in which case it should not be added or multiple - # migrations with the same version number errors will occur. - unless ActiveRecord::Migrator.migrations_paths.include? migrations_path - ActiveRecord::Migrator.migrations_paths << migrations_path - end - end - end - end - # # Determines if the database is functional # diff --git a/lib/msf/core/db_manager/migration.rb b/lib/msf/core/db_manager/migration.rb index 58a9fcb201..5d98eb960e 100644 --- a/lib/msf/core/db_manager/migration.rb +++ b/lib/msf/core/db_manager/migration.rb @@ -1,5 +1,31 @@ # -*- coding: binary -*- module Msf::DBManager::Migration + # Loads Metasploit Data Models and adds its migrations to migrations paths. + # + # @return [void] + def add_rails_engine_migration_paths + unless defined? ActiveRecord + fail "Bundle installed '--without #{Bundler.settings.without.join(' ')}'. To clear the without option do " \ + "`bundle install --without ''` (the --without flag with an empty string) or `rm -rf .bundle` to remove " \ + "the .bundle/config manually and then `bundle install`" + end + + Rails.application.railties.engines.each do |engine| + migrations_paths = engine.paths['db/migrate'].existent_directories + + migrations_paths.each do |migrations_path| + # Since ActiveRecord::Migrator.migrations_paths can persist between + # instances of Msf::DBManager, such as in specs, + # migrations_path may already be part of + # migrations_paths, in which case it should not be added or multiple + # migrations with the same version number errors will occur. + unless ActiveRecord::Migrator.migrations_paths.include? migrations_path + ActiveRecord::Migrator.migrations_paths << migrations_path + end + end + end + end + # Migrate database to latest schema version. # # @param verbose [Boolean] see ActiveRecord::Migration.verbose