class PerconaMigrator::ConnectionDetails

Holds the parameters of the DB connection and formats them to string

Attributes

connection_data[R]

Public Class Methods

new(connection_data) click to toggle source

Constructor

@param [Hash] connection parametes as used in establish_conneciton

# File lib/percona_migrator/connection_details.rb, line 8
def initialize(connection_data)
  @connection_data = connection_data
end

Public Instance Methods

database() click to toggle source

TODO: Doesn't the abstract adapter already handle this somehow? Returns the database name. If PERCONA_DB_NAME is passed its value will be used instead

Returns the database name

@return [String]

# File lib/percona_migrator/connection_details.rb, line 27
def database
  ENV.fetch('PERCONA_DB_NAME', connection_data[:database])
end
password_argument() click to toggle source

Returns the password fragment of the details string if a password is passed

@return [String]

# File lib/percona_migrator/connection_details.rb, line 34
def password_argument
  if password.present?
    "-p #{password}"
  else
    ''
  end
end
to_s() click to toggle source

Returns the details formatted as an string to be used with pt-online-schema-change. It follows the mysql client's format.

@return [String]

# File lib/percona_migrator/connection_details.rb, line 16
def to_s
  @to_s ||= "-h #{host} -u #{user} #{password_argument}"
end

Private Instance Methods

host() click to toggle source

Returns the database host name, defaulting to localhost. If PERCONA_DB_HOST is passed its value will be used instead

@return [String]

# File lib/percona_migrator/connection_details.rb, line 50
def host
  ENV.fetch('PERCONA_DB_HOST', connection_data[:host]) || 'localhost'
end
password() click to toggle source

Returns the database user's password. If PERCONA_DB_PASSWORD is passed its value will be used instead

@return [String]

# File lib/percona_migrator/connection_details.rb, line 66
def password
  ENV.fetch('PERCONA_DB_PASSWORD', connection_data[:password])
end
user() click to toggle source

Returns the database user. If PERCONA_DB_USER is passed its value will be used instead

@return [String]

# File lib/percona_migrator/connection_details.rb, line 58
def user
  ENV.fetch('PERCONA_DB_USER', connection_data[:username])
end