Sha256: d0772866c79c9f5fe7a0772a6c2a22400d40bcde6d340a9c40b51fd45d1eb939

Contents?: true

Size: 882 Bytes

Versions: 7

Compression:

Stored size: 882 Bytes

Contents

class Transferer
  def transfer_table( table_name, options = {} )
    options = OpenStruct.new( {page_size: 10000, dry_run: false}.merge( options ) )
    total_records = @src_db[table_name].count
    logger.info "transferring #{total_records}"
    column_names = @src_db.schema(table_name.to_sym).map( &:first )

    @src_db[table_name].each_page(options.page_size) do |page|
      logger.info "#{page.sql} of #{total_records}"
      unless options.dry_run
        @dst_db.transaction do
          rows_ary = []
          page.each do |row_hash|
            rows_ary << row_hash.values
          end
          @dst_db[table_name.to_sym].import column_names, rows_ary
        end
      end
    end
  end

  # copy the data in the tables
  def transfer
    create
    transfer_tables
    index
  end

  def self.transfer( src_db, dst_db )
    new( src_db, dst_db ).transfer
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
wyrm-0.2.1 lib/wyrm/transferer.rb
wyrm-0.2.0 lib/wyrm/transferer.rb
wyrm-0.1.4 lib/wyrm/transferer.rb
wyrm-0.1.3 lib/wyrm/transferer.rb
wyrm-0.1.2 lib/wyrm/transferer.rb
wyrm-0.1.1 lib/wyrm/transferer.rb
wyrm-0.1.0 lib/wyrm/transferer.rb