Sha256: 09c639acd0a6b7b9823cd57e7c9605ecdd2a9b7d67d0f28012128c861193726b

Contents?: true

Size: 1.14 KB

Versions: 6

Compression:

Stored size: 1.14 KB

Contents

module Dumper
  module Database
    class MySQL < Base
      DUMP_TOOL = 'mysqldump'
      FILE_EXT = 'sql.gz'

      def command
        "cd #{tmpdir} && #{dump_tool_path} #{connection_options} #{additional_options} #{@config[:database]} | gzip > #{filename}"
      end

      def connection_options
        [ :host, :port, :username, :password ].map do |option|
          next if @config[option].blank?
          "--#{option}='#{@config[option]}'".gsub('--username', '--user')
        end.compact.join(' ')
      end

      def additional_options
        '--single-transaction'
      end

      def set_config_for(rails_env=nil)
        return unless defined?(ActiveRecord::Base) &&
          ActiveRecord::Base.configurations &&
          (config = ActiveRecord::Base.configurations[rails_env]) &&
          %w(mysql mysql2 mysql2spatial).include?(config['adapter'])

        @config = {
          :host => config['host'],
          :port => config['port'],
          :username => config['username'],
          :password => config['password'],
          :database => config['database'],
          :dump_tool => dump_tool_path
        }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dumper-1.5.0 lib/dumper/database/mysql.rb
dumper-1.4.5 lib/dumper/database/mysql.rb
dumper-1.4.4 lib/dumper/database/mysql.rb
dumper-1.4.3 lib/dumper/database/mysql.rb
dumper-1.4.2 lib/dumper/database/mysql.rb
dumper-1.4.1 lib/dumper/database/mysql.rb