created some utility scripts

This commit is contained in:
Chris Anderson 2008-08-03 14:17:58 -07:00
parent 66c1f0bb20
commit fbccbd73e0
2 changed files with 57 additions and 0 deletions

30
utils/subset.rb Normal file
View file

@ -0,0 +1,30 @@
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