Sha256: 39787106cbe03e4770b3076775ad8fe822f68d009029e2edb7d6f709efcd4a8d

Contents?: true

Size: 761 Bytes

Versions: 163

Compression:

Stored size: 761 Bytes

Contents

require 'rubygems'
require 'couchrest'

# subset.rb replicates a percentage of a database to a fresh database.
# use it to create a smaller dataset on which to prototype views.

# specify the source database
source = CouchRest.new("http://127.0.0.1:5984").database('source-db')

# specify the target database
target = CouchRest.new("http://127.0.0.1:5984").database('target-db')

# pager efficiently yields all view rows
pager = CouchRest::Pager.new(source)

pager.all_docs(1000) do |rows|  
  docs = rows.collect do |r|
    # the percentage of docs to clone
    next if rand > 0.1 
    doc = source.get(r['id'])
    doc.delete('_rev')
    doc      
  end.compact
  puts docs.length
  next if docs.empty?

  puts docs.first['_id']
  target.bulk_save(docs)
end

Version data entries

163 entries across 163 versions & 31 rubygems

Version Path
couchrest-2.0.1 utils/subset.rb
couchrest-2.0.0 utils/subset.rb
couchrest-2.0.0.rc3 utils/subset.rb
couchrest-2.0.0.rc2 utils/subset.rb
couchrest-2.0.0.rc1 utils/subset.rb
couchrest-2.0.0.beta2 utils/subset.rb
couchrest-2.0.0.beta1 utils/subset.rb
couchrest-1.2.1 utils/subset.rb
dpla-couchrest-1.2.1.pre.dpla utils/subset.rb
brianmario-couchrest-0.23 utils/subset.rb
derfred-couchrest-0.12.6.3 utils/subset.rb
derfred-couchrest-0.12.6 utils/subset.rb
gbuesing-couchrest-0.23 utils/subset.rb
glasner-couchrest-0.2.2 utils/subset.rb
gohanlonllc-couchrest-0.2.3.1 utils/subset.rb
halfninja-couchrest-0.23.2 utils/subset.rb
halfninja-couchrest-0.23.3 utils/subset.rb
jchris-couchrest-0.12.2 utils/subset.rb
jchris-couchrest-0.12.4 utils/subset.rb
jchris-couchrest-0.12.5 utils/subset.rb