Thursday, September 17, 2009

Deploying the Latest

‹prev | My Chain | next›

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 list
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
Similarly, this method dumps alternate preparations for recipes:
# 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
I move those JSON into a new data seed directory:
cstrom@jaynestown:~/repos/eee-code$ mkdir couch/seed2
cstrom@jaynestown:~/repos/eee-code$ cd couch/seed2
cstrom@jaynestown:~/repos/eee-code/couch/seed2$ mv /tmp/*json .
Then I use my couch_docs gem to load the JSON into my local CouchDB database:
cstrom@jaynestown:~/repos/eee-code/couch/seed2$ couch-docs load . http://localhost:5984/eee
To 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_app
cstrom@jaynestown:~/repos/eee-code$ rake vlad:update vlad:migrate vlad:start_app
With that, I have my new features deployed: an updated recipe and a recipe with alternate preparations.

No comments:

Post a Comment