Module: Msf::DBManager::Migration

Included in:
Msf::DBManager
Defined in:
lib/msf/core/db_manager/migration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#migratedBoolean

Flag to indicate database migration has completed


42
43
44
# File 'lib/msf/core/db_manager/migration.rb', line 42

def migrated
  @migrated
end

Instance Method Details

#migrate(verbose = false) ⇒ Array<ActiveRecord::MigrationProxy] List of migrations that ran.

Migrate database to latest schema version.

See Also:

  • ActiveRecord::Migrator.migrate

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/msf/core/db_manager/migration.rb', line 11

def migrate(verbose=false)
  ran = []
  ActiveRecord::Migration.verbose = verbose

  ActiveRecord::Base.connection_pool.with_connection do
    begin
      ran = ActiveRecord::Migrator.migrate(
          ActiveRecord::Migrator.migrations_paths
      )
    # ActiveRecord::Migrator#migrate rescues all errors and re-raises them
    # as StandardError
    rescue StandardError => error
      self.error = error
      elog("DB.migrate threw an exception: #{error}")
      dlog("Call stack:\n#{error.backtrace.join "\n"}")
    end
  end

  # Since the connections that existed before the migrations ran could
  # have outdated column information, reset column information for all
  # ActiveRecord::Base descendents to prevent missing method errors for
  # column methods for columns created in migrations after the column
  # information was cached.
  reset_column_information

  return ran
end