Sha256: 50ce0c3af951ee7ec00305d4b676456f7a5f62d624a641d5b4b406b7d087f8e7

Contents?: true

Size: 1.13 KB

Versions: 15

Compression:

Stored size: 1.13 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).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

15 entries across 15 versions & 1 rubygems

Version Path
dumper-1.4.0 lib/dumper/database/mysql.rb
dumper-1.3.7 lib/dumper/database/mysql.rb
dumper-1.3.6 lib/dumper/database/mysql.rb
dumper-1.3.5 lib/dumper/database/mysql.rb
dumper-1.3.4 lib/dumper/database/mysql.rb
dumper-1.3.3 lib/dumper/database/mysql.rb
dumper-1.3.2 lib/dumper/database/mysql.rb
dumper-1.3.1 lib/dumper/database/mysql.rb
dumper-1.3.0 lib/dumper/database/mysql.rb
dumper-1.2.1 lib/dumper/database/mysql.rb
dumper-1.2.0 lib/dumper/database/mysql.rb
dumper-1.1.3 lib/dumper/database/mysql.rb
dumper-1.1.2 lib/dumper/database/mysql.rb
dumper-1.1.1 lib/dumper/database/mysql.rb
dumper-1.1.0 lib/dumper/database/mysql.rb