module ActiveRecord::ConnectionHandling

Public Instance Methods

mysql2_ghost_connection(config) click to toggle source

Establishes a connection to the database that's used by all Active Record objects.

# File lib/active_record/connection_adapters/mysql2_ghost_adapter.rb, line 10
def mysql2_ghost_connection(config)
  config = config.symbolize_keys
  config[:flags] ||= 0

  if config[:flags].is_a? Array
    config[:flags].push 'FOUND_ROWS'.freeze
  else
    config[:flags] |= Mysql2::Client::FOUND_ROWS
  end

  client = Mysql2::Client.new(config)
  if GhostAdapter::Internal.ghost_migration_enabeld?
    dry_run = ENV['DRY_RUN'] == '1'
    GhostAdapter::VersionChecker.validate_executable! unless ENV['SKIP_GHOST_VERSION_CHECK'] == '1'
    ConnectionAdapters::Mysql2GhostAdapter.new(client, logger, nil, config, dry_run: dry_run)
  else
    ConnectionAdapters::Mysql2Adapter.new(client, logger, nil, config)
  end
rescue Mysql2::Error => e
  raise ActiveRecord::NoDatabaseError if e.message.include?('Unknown database')

  raise
end