class Departure::AlterArgument

Represents the '–alter' argument of Percona's pt-online-schema-change See www.percona.com/doc/percona-toolkit/2.0/pt-online-schema-change.html

Constants

ALTER_TABLE_REGEX

Attributes

statement[R]
table_name[R]

Public Class Methods

new(statement) click to toggle source

Constructor

@param statement [String] @raise [InvalidAlterStatement] if the statement is not an ALTER TABLE

# File lib/departure/alter_argument.rb, line 15
def initialize(statement)
  @statement = statement

  match = statement.match(ALTER_TABLE_REGEX)
  raise InvalidAlterStatement unless match
  # Separates the ALTER TABLE from the table_name
  #
  # Removes the grave marks, if they are there, so we can get the table_name
  @table_name = String(match)
                  .split(' ')[2]
                  .delete('`')
end

Public Instance Methods

to_s() click to toggle source

Returns the '–alter' pt-online-schema-change argument as a string. See www.percona.com/doc/percona-toolkit/2.0/pt-online-schema-change.html

# File lib/departure/alter_argument.rb, line 30
def to_s
  "--alter \"#{parsed_statement}\""
end

Private Instance Methods

parsed_statement() click to toggle source

Removes the 'ALTER TABLE' portion of the SQL statement

@return [String]

# File lib/departure/alter_argument.rb, line 41
def parsed_statement
  @parsed_statement ||= statement
    .gsub(ALTER_TABLE_REGEX, '')
    .gsub('`', '\\\`')
    .gsub(/\\n/, '')
    .gsub('"', '\\\"')
end