Sha256: 55260c105c7886917fedcb5bda6bfcab42ba417611dc924a13d40d90d3e74827

Contents?: true

Size: 761 Bytes

Versions: 12

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://localhost:5984").database('source-db')

# specify the target database
target = CouchRest.new("http://localhost: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

12 entries across 12 versions & 3 rubygems

Version Path
jchris-couchrest-0.9.10 utils/subset.rb
jchris-couchrest-0.9.11 utils/subset.rb
jchris-couchrest-0.9.12 utils/subset.rb
jchris-couchrest-0.9.4 utils/subset.rb
jchris-couchrest-0.9.5 utils/subset.rb
jchris-couchrest-0.9.6 utils/subset.rb
jchris-couchrest-0.9.7 utils/subset.rb
jchris-couchrest-0.9.8 utils/subset.rb
jchris-couchrest-0.9.9 utils/subset.rb
juozasg-couchrest-0.10.1 utils/subset.rb
juozasg-couchrest-0.10.13 utils/subset.rb
topfunky-couchrest-0.9.4 utils/subset.rb