Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Migrations now work with proxied models, using streaming request for …

…first design view fetch to prevent timeout
  • Loading branch information...
commit 7f2eb65e7ccd328fca500854e4b6f5ea3801b5d8 1 parent 770fb6d
@samlown samlown authored
View
7 lib/couchrest/model/designs/design.rb
@@ -92,6 +92,7 @@ def migrate(db = nil, &block)
db ||= database
doc = load_from_database(db)
cleanup = nil
+ id = self['_id']
if !doc
# no need to migrate, just save it
@@ -100,7 +101,7 @@ def migrate(db = nil, &block)
result = :created
elsif doc['couchrest-hash'] != checksum
- id = self['_id'] + "_migration"
+ id += "_migration"
# Delete current migration if there is one
old_migration = load_from_database(db, id)
@@ -131,7 +132,9 @@ def migrate(db = nil, &block)
view = new_doc['views'][name]
params = {:limit => 1}
params[:reduce] = false if view['reduce']
- db.view("#{id}/_view/#{name}", params)
+ db.view("#{id}/_view/#{name}", params) do |res|
+ # Block to use streamer!
+ end
end
# Provide the result in block
View
8 lib/couchrest/model/migrations.rb → lib/couchrest/model/migrate.rb
@@ -52,7 +52,7 @@ def self.migrate_each_model(models, db = nil)
callbacks = [ ]
models.each do |model|
model.design_docs.each do |design|
- callbacks << migrate_design(model, design, db = nil)
+ callbacks << migrate_design(model, design, db)
end
end
callbacks
@@ -63,7 +63,7 @@ def self.migrate_each_proxying_model(models)
models.each do |model|
submodels = model.proxied_model_names.map{|n| n.constantize}
model.all.each do |base|
- puts "Migrating proxied models for #{model}:\"#{base.send(model.proxy_database_method)}\""
+ puts "Finding proxied models for #{model}: \"#{base.send(model.proxy_database_method)}\""
callbacks += migrate_each_model(submodels, base.proxy_database)
end
end
@@ -80,8 +80,8 @@ def self.migrate_design(model, design, db = nil)
end
def self.cleanup(methods)
- callbacks.compact.each do |cb|
- name = "/#{cb[:db].name}/#{db[:design]['_id']}"
+ methods.compact.each do |cb|
+ name = "/#{cb[:db].name}/#{cb[:design]['_id']}"
puts "Activating new design: #{name}"
cb[:proc].call
end
View
2  lib/couchrest/model/proxyable.rb
@@ -17,7 +17,7 @@ module ClassMethods
def proxy_for(assoc_name, options = {})
db_method = options[:database_method] || "proxy_database"
options[:class_name] ||= assoc_name.to_s.singularize.camelize
- proxied_model_names << options[:class_name]
+ proxied_model_names << options[:class_name] unless proxied_model_names.include?(options[:class_name])
class_eval <<-EOS, __FILE__, __LINE__ + 1
def #{assoc_name}
@#{assoc_name} ||= CouchRest::Model::Proxyable::ModelProxy.new(::#{options[:class_name]}, self, self.class.to_s.underscore, #{db_method})
View
3  lib/couchrest_model.rb
@@ -56,6 +56,9 @@
require "couchrest/model/embeddable"
require "couchrest/model/base"
+# Design Migration support
+require "couchrest/model/migrate.rb"
+
# Add rails support *after* everything has loaded
if defined?(Rails)
require "couchrest/railtie"
View
2  spec/unit/designs/design_spec.rb
@@ -179,7 +179,7 @@ class DesignSampleModelMigrate < DesignSampleModelBase
end
it "should create new design if non exists" do
- @db.should_receive(:view)
+ @db.should_receive(:view).with("#{@doc['_id']}/_view/#{@doc['views'].keys.first}", {:limit => 1, :reduce => false})
callback = @doc.migrate do |res|
res.should eql(:created)
end
Please sign in to comment.
Something went wrong with that request. Please try again.