Class: PerconaMigrator::CliGenerator
- Inherits:
-
Object
- Object
- PerconaMigrator::CliGenerator
- Defined in:
- lib/percona_migrator/cli_generator.rb
Overview
Generates the equivalent Percona’s pt-online-schema-change command to the given SQL statement
–no-check-alter is used to allow running CHANGE COLUMN statements. For
more details, check: www.percona.com/doc/percona-toolkit/2.2/pt-online-schema-change.html#cmdoption-pt-online-schema-change--[no]check-alter
Constant Summary collapse
- COMMAND_NAME =
'pt-online-schema-change'.freeze
- DEFAULT_OPTIONS =
Set.new( [ Option.new('execute'), Option.new('statistics'), Option.new('alter-foreign-keys-method', 'auto'), Option.new('no-check-alter') ] ).freeze
Instance Method Summary collapse
-
#generate(table_name, statement) ⇒ String
Generates the percona command.
-
#initialize(connection_details) ⇒ CliGenerator
constructor
TODO: Better doc.
-
#parse_statement(statement) ⇒ String
Generates the percona command for a raw MySQL statement.
Constructor Details
#initialize(connection_details) ⇒ CliGenerator
TODO: Better doc.
Constructor. Specify any arguments to pass to pt-online-schema-change passing the PERCONA_ARGS env var when executing the migration
32 33 34 |
# File 'lib/percona_migrator/cli_generator.rb', line 32 def initialize(connection_details) @connection_details = 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
45 46 47 48 49 50 |
# File 'lib/percona_migrator/cli_generator.rb', line 45 def generate(table_name, statement) alter_argument = AlterArgument.new(statement) dsn = DSN.new(connection_details.database, table_name) "#{command} #{} #{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
60 61 62 63 64 65 |
# File 'lib/percona_migrator/cli_generator.rb', line 60 def parse_statement(statement) alter_argument = AlterArgument.new(statement) dsn = DSN.new(connection_details.database, alter_argument.table_name) "#{command} #{} #{dsn} #{alter_argument}" end |