Sha256: 428b233974b89fec03e9b777c08011b0b457413e0204b099d7197b0b9d6983c8

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

module PerconaMigrator

  # 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 = /ALTER TABLE `(\w+)` /

    # Constructor
    #
    # @param statement [String]
    def initialize(statement)
      @statement = statement
    end

    # Returns the '--alter' pt-online-schema-change argumment as a string. See
    # https://www.percona.com/doc/percona-toolkit/2.0/pt-online-schema-change.html
    def to_s
      "--alter \"#{parsed_statement}\""
    end

    # Returns the name of the table the alter statement refers to
    #
    # @return [String]
    def table_name
      statement.match(ALTER_TABLE_REGEX).captures[0]
    end

    private

    attr_reader :statement

    # Removes the 'ALTER TABLE' portion of the SQL statement
    #
    # @return [String]
    def parsed_statement
      @parsed_statement ||= statement
        .gsub(ALTER_TABLE_REGEX, '')
        .gsub('`','\\\`')
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
percona_migrator-0.1.0.rc.5 lib/percona_migrator/alter_argument.rb
percona_migrator-0.1.0.rc.4 lib/percona_migrator/alter_argument.rb
percona_migrator-0.1.0.rc.3 lib/percona_migrator/alter_argument.rb