class Departure::Runner
It executes pt-online-schema-change commands in a new process and gets its output and status
Attributes
cli_generator[R]
error_log_path[R]
logger[R]
mysql_adapter[R]
Public Class Methods
new(logger, cli_generator, mysql_adapter, config = Departure.configuration)
click to toggle source
Constructor
@param logger [#say, write] @param cli_generator
[CliGenerator] @param mysql_adapter
[ActiveRecord::ConnectionAdapter] it must implement
#execute and #raw_connection
# File lib/departure/runner.rb, line 13 def initialize(logger, cli_generator, mysql_adapter, config = Departure.configuration) @logger = logger @cli_generator = cli_generator @mysql_adapter = mysql_adapter @error_log_path = config.error_log_path end
Public Instance Methods
affected_rows()
click to toggle source
Returns the number of rows affected by the last UPDATE, DELETE or INSERT statements
@return [Integer]
# File lib/departure/runner.rb, line 37 def affected_rows mysql_adapter.raw_connection.affected_rows end
execute(command_line)
click to toggle source
TODO: rename it so we don't confuse it with AR's execute
Runs and logs the given command
@param command_line [String] @return [Boolean]
# File lib/departure/runner.rb, line 46 def execute(command_line) Command.new(command_line, error_log_path, logger).run end
query(sql)
click to toggle source
Executes the passed sql statement using pt-online-schema-change for ALTER TABLE statements, or the specified mysql adapter otherwise.
@param sql [String]
# File lib/departure/runner.rb, line 24 def query(sql) if alter_statement?(sql) command_line = cli_generator.parse_statement(sql) execute(command_line) else mysql_adapter.execute(sql) end end
Private Instance Methods
alter_statement?(sql)
click to toggle source
Checks whether the sql statement is an ALTER TABLE
@param sql [String] @return [Boolean]
# File lib/departure/runner.rb, line 58 def alter_statement?(sql) sql =~ /\Aalter table/i end