Skip to content

Commit

Permalink
Fix deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
adfoster-r7 committed Jun 12, 2024
1 parent e22c494 commit 218250d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ GEM
activesupport (~> 7.0)
railties (~> 7.0)
zeitwerk
metasploit-credential (6.0.9)
metasploit-credential (6.0.10)
metasploit-concern
metasploit-model
metasploit_data_models (>= 5.0.0)
Expand All @@ -304,7 +304,7 @@ GEM
activesupport (~> 7.0)
railties (~> 7.0)
metasploit-payloads (2.0.166)
metasploit_data_models (6.0.3)
metasploit_data_models (6.0.5)
activerecord (~> 7.0)
activesupport (~> 7.0)
arel-helpers
Expand Down Expand Up @@ -354,7 +354,7 @@ GEM
packetfu (2.0.0)
pcaprub (~> 0.13.1)
parallel (1.25.1)
parser (3.3.2.0)
parser (3.3.3.0)
ast (~> 2.4.1)
racc
patch_finder (1.0.2)
Expand Down
21 changes: 12 additions & 9 deletions lib/msf/core/db_manager/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ def migrate(config=nil, verbose=false)
ActiveRecord::Migration.verbose = verbose
ActiveRecord::Base.connection_pool.with_connection do
begin
context = default_migration_context
if needs_migration?(context)
ran = context.migrate
ran = nil
with_migration_context do |context|
if context.needs_migration?
ran = context.migrate
end
end

# ActiveRecord::Migrator#migrate rescues all errors and re-raises them
# as StandardError
rescue StandardError => error
Expand All @@ -62,10 +65,9 @@ def migrate(config=nil, verbose=false)

# Determine if the currently established database connection needs migration
#
# @param [ActiveRecord::MigrationContext,snil] context The migration context to check. Will default if not supplied
# @return [Boolean] True if migration is required, false otherwise
def needs_migration?(context = default_migration_context)
ActiveRecord::Base.connection_pool.with_connection do
def needs_migration?
with_migration_context do |context|
return context.needs_migration?
end
end
Expand All @@ -77,9 +79,10 @@ def needs_migration?(context = default_migration_context)

private

# @return [ActiveRecord::MigrationContext]
def default_migration_context
ActiveRecord::MigrationContext.new(gather_engine_migration_paths, ActiveRecord::SchemaMigration)
def with_migration_context
ActiveRecord::Base.connection_pool.with_connection do
yield ActiveRecord::MigrationContext.new(gather_engine_migration_paths)
end
end

# Loads gathers migration paths from all loaded Rails engines.
Expand Down
2 changes: 1 addition & 1 deletion spec/support/shared/examples/msf/db_manager/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def migrate
end

before(:example) do
mockContext = ActiveRecord::MigrationContext.new(nil, ActiveRecord::SchemaMigration)
mockContext = ActiveRecord::MigrationContext.new(nil)
expect(ActiveRecord::MigrationContext).to receive(:new).and_return(mockContext)
expect(mockContext).to receive(:needs_migration?).and_return(true)
expect(mockContext).to receive(:migrate).and_raise(standard_error)
Expand Down

0 comments on commit 218250d

Please sign in to comment.