lib/couchrest/model/utils/migrate.rb in couchrest_model-2.1.0.beta1 vs lib/couchrest/model/utils/migrate.rb in couchrest_model-2.1.0.beta2
- old
+ new
@@ -20,12 +20,27 @@
# # Migrate all models and submodels of proxies
# CouchRest::Model::Utils::Migrate.all_models_and_proxies
#
# Typically however you'd want to run these methods from the rake tasks:
#
- # $ rake couchrest:migrate_with_proxies
+ # $ rake couchrest:designs:migrate_with_proxies
#
+ # In production environments, you sometimes want to prepare large view
+ # indexes that take a long term to generate before activating them. To
+ # support this scenario we provide the `:activate` option:
+ #
+ # # Prepare all models, but do not activate
+ # CouchRest::Model::Utils::Migrate.all_models(activate: false)
+ #
+ # Or from Rake:
+ #
+ # $ rake couchrest:designs:prepare
+ #
+ # Once finished, just before uploading your code you can repeat without
+ # the `activate` option so that the view indexes are ready for the new
+ # designs.
+ #
# NOTE: This is an experimental feature that is not yet properly tested.
#
module Migrate
extend self
@@ -39,19 +54,20 @@
end
end
# Go through each class that inherits from CouchRest::Model::Base and
# attempt to migrate the design documents.
- def all_models
+ def all_models(opts = {})
+ opts.reverse_merge!(activate: true, with_proxies: false)
callbacks = migrate_each_model(find_models)
- cleanup(callbacks)
+ callbacks += migrate_each_proxying_model(find_proxying_models) if opts[:with_proxies]
+ activate_designs(callbacks) if opts[:activate]
end
- def all_models_and_proxies
- callbacks = migrate_each_model(find_models)
- callbacks += migrate_each_proxying_model(find_proxying_models)
- cleanup(callbacks)
+ def all_models_and_proxies(opts = {})
+ opts[:with_proxies] = true
+ all_models(opts)
end
protected
def find_models
@@ -96,10 +112,10 @@
end
# Return the callback hash if there is one
callback ? {:design => design, :proc => callback, :db => db || model.database} : nil
end
- def cleanup(methods)
+ def activate_designs(methods)
methods.compact.each do |cb|
name = "/#{cb[:db].name}/#{cb[:design]['_id']}"
puts "Activating new design: #{name}"
cb[:proc].call
end