lib/departure/alter_argument.rb in departure-6.1.0 vs lib/departure/alter_argument.rb in departure-6.2.0

- old
+ new

@@ -2,11 +2,11 @@ class InvalidAlterStatement < StandardError; end # Represents the '--alter' argument of Percona's pt-online-schema-change # See https://www.percona.com/doc/percona-toolkit/2.0/pt-online-schema-change.html class AlterArgument - ALTER_TABLE_REGEX = /\AALTER TABLE `(\w+)` / + ALTER_TABLE_REGEX = /\AALTER TABLE [^\s]*[\n]* / attr_reader :table_name # Constructor # @@ -15,12 +15,16 @@ def initialize(statement) @statement = statement match = statement.match(ALTER_TABLE_REGEX) raise InvalidAlterStatement unless match - - @table_name = match.captures[0] + # 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 # Returns the '--alter' pt-online-schema-change argument as a string. See # https://www.percona.com/doc/percona-toolkit/2.0/pt-online-schema-change.html def to_s @@ -36,8 +40,10 @@ # @return [String] def parsed_statement @parsed_statement ||= statement .gsub(ALTER_TABLE_REGEX, '') .gsub('`', '\\\`') + .gsub(/\\n/, '') + .gsub('"', '\\\"') end end end