Picking up where I left off yesterday, I use these
./script/console
methods to dump JSON documents describing recipe updates from the legacy Rails application:# Traverse the linked list of recipe updates, building up the listSimilarly, this method dumps alternate preparations for recipes:
def update_list(recipe, list=[])
if recipe.is_replacement?
update_list(recipe.replacement_for,
list + [{:id => recipe.uri.gsub(/\//, '-')}])
else
list + [{:id => recipe.uri.gsub(/\//, '-')}]
end
end
# For every recipe update, dump a JSON update document that includes
# the entire linked list (from update_list)
RecipeUpdate.find(:all).
reject { |update| update.successor.has_replacement? }.
map {|update| {:type => "Update",
:name => update.successor.title.downcase,
:updates => update_list(update.successor).reverse } }.
each do |update|
filename = "/tmp/#{update[:name].gsub(/\s+/, '_')}_update.json"
file = File.new(filename, "w+")
file.write(update.to_json)
file.close
end
# For every group of similar recipes, dump a JSON document that
# includes the list.
RecipeGroup.find(:all).each do |group|
alternate = { :type => "Alternative",
:name => group.name,
:recipes => group.recipes.map{|r| r.uri.gsub(/\//, '-')} }
filename = "/tmp/#{group.name.gsub(/\s+/, '_')}_alternative.json"
file = File.new(filename, "w+")
file.write(alternate.to_json)
file.close
end
# For every group of similar recipes, dump a JSON document thatI move those JSON into a new data seed directory:
# includes the list.
RecipeGroup.find(:all).each do |group|
alternate = { :type => "Alternative",
:name => group.name,
:recipes => group.recipes.map{|r| r.uri.gsub(/\//, '-')} }
filename = "/tmp/#{group.name.gsub(/\s+/, '_')}_alternative.json"
file = File.new(filename, "w+")
file.write(alternate.to_json)
file.close
end
cstrom@jaynestown:~/repos/eee-code$ mkdir couch/seed2Then I use my couch_docs gem to load the JSON into my local CouchDB database:
cstrom@jaynestown:~/repos/eee-code$ cd couch/seed2
cstrom@jaynestown:~/repos/eee-code/couch/seed2$ mv /tmp/*json .
cstrom@jaynestown:~/repos/eee-code/couch/seed2$ couch-docs load . http://localhost:5984/eeeTo make sure that everything is working I check the pizza dough recipe, which has been updated many times:
Yup, the updates are working. How about the alternate preparations?
Yup.
Last up tonight, I indulge in a little #yerdoinitwrong by manually copying the seed data over to the beta site. After loading it with
couch-docs
, I deploy with vlad:cstrom@jaynestown:~/repos/eee-code$ rake vlad:stop_appWith that, I have my new features deployed: an updated recipe and a recipe with alternate preparations.
cstrom@jaynestown:~/repos/eee-code$ rake vlad:update vlad:migrate vlad:start_app
No comments:
Post a Comment