Class: Departure::Runner
- Inherits:
-
Object
- Object
- Departure::Runner
- Defined in:
- lib/departure/runner.rb
Overview
It executes pt-online-schema-change commands in a new process and gets its output and status
Constant Summary collapse
- COMMAND_NOT_FOUND =
127
Instance Method Summary collapse
-
#affected_rows ⇒ Integer
Returns the number of rows affected by the last UPDATE, DELETE or INSERT statements.
-
#execute(command) ⇒ Boolean
TODO: rename it so we don’t confuse it with AR’s #execute Runs and logs the given command.
-
#initialize(logger, cli_generator, mysql_adapter, config = Departure.configuration) ⇒ Runner
constructor
Constructor.
-
#query(sql) ⇒ Object
Executes the passed sql statement using pt-online-schema-change for ALTER TABLE statements, or the specified mysql adapter otherwise.
Constructor Details
#initialize(logger, cli_generator, mysql_adapter, config = Departure.configuration) ⇒ Runner
Constructor
16 17 18 19 20 21 22 |
# File 'lib/departure/runner.rb', line 16 def initialize(logger, cli_generator, mysql_adapter, config = Departure.configuration) @logger = logger @cli_generator = cli_generator @mysql_adapter = mysql_adapter @status = nil @config = config end |
Instance Method Details
#affected_rows ⇒ Integer
Returns the number of rows affected by the last UPDATE, DELETE or INSERT statements
41 42 43 |
# File 'lib/departure/runner.rb', line 41 def affected_rows mysql_adapter.raw_connection.affected_rows end |
#execute(command) ⇒ Boolean
TODO: rename it so we don’t confuse it with AR’s #execute Runs and logs the given command
50 51 52 53 54 55 |
# File 'lib/departure/runner.rb', line 50 def execute(command) @command = command logging { run_command } validate_status status end |
#query(sql) ⇒ Object
Executes the passed sql statement using pt-online-schema-change for ALTER TABLE statements, or the specified mysql adapter otherwise.
28 29 30 31 32 33 34 35 |
# File 'lib/departure/runner.rb', line 28 def query(sql) if alter_statement?(sql) command = cli_generator.parse_statement(sql) execute(command) else mysql_adapter.execute(sql) end end |