Class: Departure::CliGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/departure/cli_generator.rb

Overview

Generates the equivalent Percona’s pt-online-schema-change command to the given SQL statement

Constant Summary collapse

BASE_COMMAND =

Command

'pt-online-schema-change'
BASE_OPTIONS =
%w(
  --execute
  --statistics
  --recursion-method=none
  --alter-foreign-keys-method=auto
)

Instance Method Summary collapse

Constructor Details

#initialize(connection_data) ⇒ CliGenerator

Constructor



43
44
45
46
47
# File 'lib/departure/cli_generator.rb', line 43

def initialize(connection_data)
  @connection_data = connection_data
  init_base_command
  add_connection_details
end

Instance Method Details

#generate(table_name, statement) ⇒ String

Generates the percona command. Fills all the connection credentials from the current AR connection, but that can be amended via ENV-vars: PERCONA_DB_HOST, PERCONA_DB_USER, PERCONA_DB_PASSWORD, PERCONA_DB_NAME Table name can’t not be amended, it populates automatically from the migration data



58
59
60
61
62
63
# File 'lib/departure/cli_generator.rb', line 58

def generate(table_name, statement)
  alter_argument = AlterArgument.new(statement)
  dsn = DSN.new(database, table_name)

  "#{self} #{dsn} #{alter_argument}"
end

#parse_statement(statement) ⇒ String

Generates the percona command for a raw MySQL statement. Fills all the connection credentials from the current AR connection, but that can amended via ENV-vars: PERCONA_DB_HOST, PERCONA_DB_USER, PERCONA_DB_PASSWORD, PERCONA_DB_NAME Table name can’t not be amended, it populates automatically from the migration data



73
74
75
76
77
78
# File 'lib/departure/cli_generator.rb', line 73

def parse_statement(statement)
  alter_argument = AlterArgument.new(statement)
  dsn = DSN.new(database, alter_argument.table_name)

  "#{self} #{dsn} #{alter_argument}"
end