Module: ActiveRecord::ConnectionHandling

Defined in:
lib/active_record/connection_adapters/percona_adapter.rb

Instance Method Summary collapse

Instance Method Details

#percona_connection(config) ⇒ Object

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



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
38
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 11

def percona_connection(config)
  mysql2_connection = mysql2_connection(config)

  config[:username] = 'root' if config[:username].nil?

  connection_details = PerconaMigrator::ConnectionDetails.new(config)
  verbose = ActiveRecord::Migration.verbose
  sanitizers = [
    PerconaMigrator::LogSanitizers::PasswordSanitizer.new(connection_details)
  ]
  percona_logger = PerconaMigrator::LoggerFactory.build(sanitizers: sanitizers, verbose: verbose)
  cli_generator = PerconaMigrator::CliGenerator.new(connection_details)

  runner = PerconaMigrator::Runner.new(
    percona_logger,
    cli_generator,
    mysql2_connection
  )

  connection_options = { mysql_adapter: mysql2_connection }

  ConnectionAdapters::PerconaMigratorAdapter.new(
    runner,
    logger,
    connection_options,
    config
  )
end