Neo4j on Heroku – Part Three

This week we learned that leaving the create_graph method accessible to the world was a bad idea. So let’s go ahead and delete that route in Sinatra, and instead create a Rake Task for it.

In Rakefile:

require 'neography/tasks'
require './neoflix.rb'

namespace :neo4j do
  task :create do
    neo = Neography::Rest.new(ENV['NEO4J_URL'] || "http://localhost:7474")
    create_graph(neo)
  end
end

That’s much better. We can create our graph locally with

rake neo4j:create

or we can run it on Heroku with

heroku run rake neo4j:create

If you create the database locally, you can transfer it to Heroku with the Backup and Restore Options.
Log in to Heroku, the go to your apps https://api.heroku.com/myapps, click on your application (I’ll click on Neoflix) then on the “addons” drop down menu on the right, select Neo4j, and you’ll see this screen come up:

You can zip up the contents of your Neo4j database to neoflix.zip and perform a restore operation.

cd neo4j/data/graph.db
zip -r neoflix.zip .

Your Neo4j addon will restart and all your data will be loaded and ready to go.

If you have followed part 1 and part 2 of this series, then you should take what you have learned and create a Neo4j demo application. Take part in the Neo4j Challenge and have a chance at winning awesome prices as well as learning a new technology.

Tagged , , , ,

One thought on “Neo4j on Heroku – Part Three

  1. [...] Neo4j on Heroku Part3 starts out: This week we learned that leaving the create_graph method accessible to the world was a bad idea. So let’s go ahead and delete that route in Sinatra, and instead create a Rake Task for it. [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 1,575 other followers

%d bloggers like this: