It isn't util

improve_associations^2
Marcos Tapajós 2010-08-03 23:11:35 -03:00
parent c7acbc07ec
commit 9466f67329
3 changed files with 1 additions and 58 deletions

View File

@ -24,7 +24,7 @@ begin
gemspec.homepage = "http://github.com/couchrest/couchrest_model"
gemspec.authors = ["J. Chris Anderson", "Matt Aimonetti", "Marcos Tapajos", "Will Leinweber", "Sam Lown"]
gemspec.extra_rdoc_files = %w( README.md LICENSE THANKS.md )
gemspec.files = %w( LICENSE README.md Rakefile THANKS.md history.txt couchrest.gemspec) + Dir["{examples,lib,spec,utils}/**/*"] - Dir["spec/tmp"]
gemspec.files = %w( LICENSE README.md Rakefile THANKS.md history.txt couchrest.gemspec) + Dir["{examples,lib,spec}/**/*"] - Dir["spec/tmp"]
gemspec.has_rdoc = true
gemspec.add_dependency("couchrest", ">= 1.0.0.beta")
gemspec.add_dependency("mime-types", ">= 1.15")

View File

@ -1,27 +0,0 @@
require 'rubygems'
require 'couchrest'
# set the source db and map view
source = CouchRest.new("http://127.0.0.1:5984").database('source-db')
source_view = 'mydesign/view-map'
# set the target db
target = CouchRest.new("http://127.0.0.1:5984").database('target-db')
pager = CouchRest::Pager.new(source)
# pager will yield once per uniq key in the source view
pager.key_reduce(source_view, 10000) do |key, values|
# create a doc from the key and the values
example_doc = {
:key => key,
:values => values.uniq
}
target.save(example_doc)
# keep us up to date with progress
puts k if (rand > 0.9)
end

View File

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