Class: Departure::Runner
- Inherits:
-
Object
- Object
- Departure::Runner
- Extended by:
- Forwardable
- Defined in:
- lib/departure/runner.rb
Overview
It executes pt-online-schema-change commands in a new process and gets its output and status
Instance Method Summary collapse
- #abandon_results! ⇒ Object
-
#affected_rows ⇒ Integer
Returns the number of rows affected by the last UPDATE, DELETE or INSERT statements.
- #database_adapter ⇒ Object
-
#execute(command_line) ⇒ 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.
- #query_options ⇒ Object
- #raw_connection ⇒ Object
Constructor Details
#initialize(logger, cli_generator, mysql_adapter, config = Departure.configuration) ⇒ Runner
Constructor
22 23 24 25 26 27 28 |
# File 'lib/departure/runner.rb', line 22 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 @redirect_stderr = config&.redirect_stderr end |
Instance Method Details
#abandon_results! ⇒ Object
34 35 36 |
# File 'lib/departure/runner.rb', line 34 def abandon_results! raw_connection.abandon_results! end |
#affected_rows ⇒ Integer
Returns the number of rows affected by the last UPDATE, DELETE or INSERT statements
63 64 65 |
# File 'lib/departure/runner.rb', line 63 def affected_rows raw_connection.affected_rows end |
#database_adapter ⇒ Object
38 39 40 |
# File 'lib/departure/runner.rb', line 38 def database_adapter @mysql_adapter end |
#execute(command_line) ⇒ Boolean
TODO: rename it so we don’t confuse it with AR’s #execute Runs and logs the given command
72 73 74 |
# File 'lib/departure/runner.rb', line 72 def execute(command_line) Command.new(command_line, error_log_path, logger, redirect_stderr).run end |
#query(sql) ⇒ Object
Executes the passed sql statement using pt-online-schema-change for ALTER TABLE statements, or the specified mysql adapter otherwise.
50 51 52 53 54 55 56 57 |
# File 'lib/departure/runner.rb', line 50 def query(sql) if alter_statement?(sql) command_line = cli_generator.parse_statement(sql) execute(command_line) else database_adapter.execute(sql) end end |
#query_options ⇒ Object
30 31 32 |
# File 'lib/departure/runner.rb', line 30 def raw_connection. end |
#raw_connection ⇒ Object
42 43 44 |
# File 'lib/departure/runner.rb', line 42 def raw_connection database_adapter.raw_connection end |